Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select a child element in jquery object

I'm new to jquery and I have a basic question now.

I have a jquery object got from a jquery selector. e.g

var obj = $('#certainTR');

Now, I want to get the element in this object and I cannot use '#certainTR > date' in a selector because '#certain' is not passed in my subroutine. Is there anyway to make a selection base on a object? Thanks a lot in advance!

like image 520
Roy Avatar asked Sep 21 '10 03:09

Roy


People also ask

How do I select a specific child in JavaScript?

Select the parent element whose child element is going to be selected. Use . querySelector() method on parent. Use the className of the child to select that particular child.

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 function in jQuery?

The children() method returns all direct children of the selected element. The DOM tree: This method only traverse a single level down the DOM tree. To traverse down multiple levels (to return grandchildren or other descendants), use the find() method.


1 Answers

use .children()

var obj = $('#certainTR'); // #certainTR
obj.children('.date'); // #certainTR > .date

I suggest you should visit Tree Traversal

like image 50
Reigel Avatar answered Sep 22 '22 21:09

Reigel