Div filter based on id

I can successfully hide divs that contains a line in id with this code:

Button:

<input type="button" id="mytest" value="filter"></input>

      

Js code:

//hides divs with class=screen3 and with 99 in its id
$('#myteste').click (function () {
    $('div.screen3[id*="99"]').hide();
});

      

Now I need to do the opposite to hide the divs that does not contain the id string in it, but I don't know how to do it.

+3


source to share


2 answers


You can do it:

$('div.screen3').not('[id~="99"]').hide(); // tests the word (delimited by spaces)

      



or

$('div.screen3').not('[id*="99"]').hide(); // tests the string

      

+4


source


Try using: not



$('#myteste').click (function () {
    $('div.screen3:not([id*="99"])').hide();
});

      

+2


source







All Articles