Member-only story
jQuery — Select Elements and Remove Event Listeners
3 min readDec 31, 2020
jQuery is a popular JavaScript for creating dynamic web pages.
In this article, we’ll look at how to using jQuery in our web apps.
:not() Selector
The :not
selector selects all elements that don't match a given selector.
For example, if we have:
<div>
<input type="checkbox" name="a">
<span>Mary</span>
</div>
<div>
<input type="checkbox" name="b">
<span>lcm</span>
</div>
<div>
<input type="checkbox" name="c" checked="checked">
<span>Peter</span>
</div>
Then we add a yellow background to all the checkboxes that are unchecked by writing:
$("input:not(:checked) + span").css("background-color", "yellow");
:nth-child() Selector
The :nth-child()
selector lets us select all elements that are the nth-child of their parent.
For example, if we have:
<div>
<ul>
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
</div>
<div>
<ul>
<li>Sam</li>
</ul>
</div>
<div>
<ul>
<li>John</li>
<li>Jane</li>
<li>Ralph</li>
<li>David</li>
</ul>
</div>