$('body > div').each(function() {
...
});
What functionality does comparing body > div provide?
This is a part of answer provided to this question
Comparing DOM elements with jQuery
.
I want to do similar thing but I am not able to understand the functionality provided by comparing two DOM objects.
That’s not a comparison. It’s a child selector. What it does is this:
So if you have HTML like this:
Then
$("div > span")will select the firstspan, because it’s a child of adiv, but it won’t select the second, because that’s a child of ap.Note that removing the child selector, and using
$("div span")will select bothspanelements, because that looks forspanelements that are descendants of adiv, not specifically children.