Reputation: 2275
I'm trying to get all the selectors and get the height on that selector:
var myDiv = $('#main-div').find('*').each(function(e){
return this.id;
});
console.log(myDiv);
What I need is get the height
and width
of every element inside #main-div
, and show into console like:
[selector, width , height]... each
Any ideas?
Upvotes: 0
Views: 104
Reputation: 79830
You can use .children() to access all the elements inside the div and use .height() and .width() on them. Something like below should work (untested),
$.each ($('#main-div').children(), function (index) {
console.log ('[' + this.tagName + ',' + $(this).height() + ',' + $(this).width() + ']');
});
DEMO here to show that it only access the immediate childrens and not goes inside the child element(s).
Upvotes: 1
Reputation: 2967
Try:
var myDiv = $('#main-div').find('*').each(function(e){
console.log( "id: " + $( this ).attr('id') + ", height:" + $( this ).height( ) + ", width: " + $( this ).width( )
});
Upvotes: 0