JQuery -.fadeOut all div except those who have these ids?

How can I pay off all divs except those who have any of these three identifiers?

#dontFadeOne
#dontFadeTwo
#dontFadeThree

I think something like this:

$("div").notAnyOf("dontFadeOne","dontFadeTwo","dontFadeThree").fadeOut();

But I can not find the "not any" function.

+3
source share
2 answers

Take a look at the .not () function:

http://api.jquery.com/not/

Since the white paper explains this quite clearly, here it is from the API website:

Delete specific items

The second version of the .not () method allows us to remove elements from the matched set, assuming that we have already found these elements in some other ways. For example, suppose our list had an identifier applied to one of its elements:

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
  <li id="notli">list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
</ul>

, getElementById(), jQuery:

$('li').not(document.getElementById('notli'))
  .css('background-color', 'red');

1, 2, 4 5. jQuery, , , , DOM .

jQuery 1.4, .not() , .filter(). , true, ; .

+4

not() :not :

$("div").not("#dontFadeOne, #dontFadeTwo, #dontFadeThree").fadeOut();

$("div").not("#dontFadeOne).not("#dontFadeTwo").not("#dontFadeThree").fadeOut();

$("div:not(#dontFadeOne):not(#dontFadeTwo):not(#dontFadeThree)").fadeOut();
+3

Source: https://habr.com/ru/post/1739392/


All Articles