<div id="container1">
<span>...</span>
</div>
<div id="container2">
<span>...</span>
</div>
Say if I have get the jQuery object $('container1'),how to find the <span>
in it?
The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field. Syntax: $(selector). select(function);
You can use the children property of getElementById() method in JavaScript to get or extract unique ids of all the DIV elements inside a DIV element.
Use document.querySelector on to select a div and then select an element within it with the given class after that. We just call querySelector on the element with the ID mydiv to select items inside that div. Therefore, innerDiv is the div with the class myclass .
If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. var myDomElement = document. getElementById( "foo" ); // A plain DOM element.
I know you have accepted an answer, I'd just like to add another way of doing this:
$("span", $container1); //This will start in your variable $container1
and then look for all spans
I haven't tested performance on these yet, so I don't know which is better. Just thought I'd let you know you have more options (:
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