I have this markup:
<div id="myElement">
<ul>
<li><a href="#1" class="myElementLink">Link 1</a></li>
<li><a href="#2" class="myElementLink">Link 2</a></li>
<li><a href="#3" class="myElementLink">Link 3</a></li>
</ul>
</div>
Which is the syntax to select all "myElementLink" within "myElement"?
Thanks for helping
Use the element element selector to select all elements inside another 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 .
The magical $()
function of jQuery can take pretty much anything you would do in regular CSS to style a particular set of elements. In your case, this would do the trick:
$('#myElement a.myElementLink');
Specifying which elements will have a particular class (ie, a.class vs .class) is much faster if possible.
You could also pass the second argument, known as the context to the jQuery function to come up with:
$('a.myElementLink', '#myElement');
Which basically says "search for the 1st argument within the 2nd argument"
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