I am using this to find all elements inside some div:
var counts = {}
var element = 'div';
$('.workspace').find('*').each(function() {
var tag = this.tagName.toLowerCase();
counts[tag] = counts[tag] || 0;
counts[tag] ++;
});
Now I am checking does element exist in counts:
if(el in counts)
And if it does I am need to get number of divs with:
counts.div but since div is string in var element I need to use counts.element and there I get error undefined because it can't find element its like I said counts.'elements'.
Basically when i use counts.div or counts.header etc I get number of how many divs are there inside some element. How can I accomplish this?
counts[element]? <-- bracket notation