Is it possible to, somehow, select a direct child of $(this)?
I have:
var obj = $(this); $("ul", obj).css('width',s*w);
And need it to act like this obj > ul
Is it possible?
Answer: Use the jQuery find() Method You can use the find() method to get the children of the $(this) selector using jQuery. The jQuery code in the following example will simply select the child <img> element and apply some CSS style on it on click of the parent <div> element.
children() is an inbuilt method in jQuery which is used to find all the children element related to that selected element. This children() method in jQuery traverse down to a single level of the selected element and return all elements. Syntax: $(selector).children()
In jQuery, you can use $('#id'). children(). length > 0 to test if an element has children.
The ("parent > child") selector selects all elements that are a direct child of the specified element.
$(this).children('ul')
returns a list of direct children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With