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
3 Answers
Reset to default 3You 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"));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745477911a4629430.html
评论列表(0条)