Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Direct child of $(this)

Tags:

jquery

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?

like image 393
curly_brackets Avatar asked May 31 '11 10:05

curly_brackets


People also ask

How do you get the children of the $( this selector?

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.

What is children() in jQuery?

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()

How to check child element in jQuery?

In jQuery, you can use $('#id'). children(). length > 0 to test if an element has children.

What will select all direct child elements in jQuery?

The ("parent > child") selector selects all elements that are a direct child of the specified element.


1 Answers

$(this).children('ul') returns a list of direct children.

like image 138
DanielB Avatar answered Sep 27 '22 16:09

DanielB