How to select elements but exclude a string or exclude an element by using JQuery

Here is the code:

<div class="content">
    <a href="#">A</a></div>
<div class="content">
    <a href="#">B</a></div>
<div class="content">
    <a href="#">C</a></div>

When one of these links is clicked, I want to perform the .hide() function on the links that are not clicked. I understand jQuery has the :not selector, but I can’t figure out how to use it in this case because it is necessary that I select the links using $(“.content a”).

There are two way to do this:

$(".content a").click(function() {
    $(".content a").not(this).hide("slow");
});

Here is the code:

<div id=content>
<tr>First</tr>
<tr>First Second</tr>
</div>

I want to know how many

element that contain “First” string but not contain “Second” string.

$("#content tr:contains('First'):not(:contains('Second'))").length;

Leave a Comment