最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how can i console the list of DOM object with javascript - Stack Overflow

programmeradmin1浏览0评论

when i get an element with jQuery and console.log() the element i can see all methods that i can do something with. but when i use javascript to show element in console it just show the element itself instead of show me methods like _.style _.accessKey and so on, like when i do $(this)[0] with jQuery. so how to see all these methods in pure javascript ?

when i get an element with jQuery and console.log() the element i can see all methods that i can do something with. but when i use javascript to show element in console it just show the element itself instead of show me methods like _.style _.accessKey and so on, like when i do $(this)[0] with jQuery. so how to see all these methods in pure javascript ?

Share Improve this question edited Nov 16, 2018 at 17:09 Amir Rezvani asked Nov 14, 2018 at 16:59 Amir RezvaniAmir Rezvani 1,51413 silver badges40 bronze badges 1
  • 1 a console log in most browsers wil show you the whole object including its methods and properties. Else you can write your own traversal function and print them out using console.log – Nikos M. Commented Nov 14, 2018 at 17:02
Add a ment  | 

3 Answers 3

Reset to default 3

You can try the following:-

var div = document.getElementsByTagName('div')[0];

console.table(div) or console.dir(div)

This will print out all the properties available in a neat table format.

use console.dir() to see all the methods for javascript DOM object.

You can try following ways to find html elements:

var x = document.getElementById('id');
console.log(x);

var y = document.getElementsByTagName('tag_name');
console.log(y);

var z = document.getElementsByClassName('class_name');
console.log(z);

and then list all methods and properties associated with that element by creating one new object and then call the function

function getAllMethods(object) {
       return Object.getOwnPropertyNames(object).filter(function(property) {
        return typeof object[property] == 'function';
}

console.log(getAllMethods("object"));
发布评论

评论列表(0)

  1. 暂无评论