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!
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.
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.
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.
use .children()
var obj = $('#certainTR'); // #certainTR
obj.children('.date'); // #certainTR > .date
I suggest you should visit Tree Traversal
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