javascript - jquery select all LI from UL's, that not in UL element with class -


is possible select elements ul, exclude ul class not-need?

<ul>     <li></li>     <li></li>     <li></li>     <li></li>     <li></li> </ul> <ul class='not-need'>     <li></li>     <li></li>     <li></li>     <li></li>     <li></li> </ul> 

you can use :not() or not() excluding element

$('ul:not(.not-need) li').css('color', 'red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <ul>    <li>1</li>    <li>2</li>    <li>3</li>    <li>4</li>    <li>5</li>  </ul>      <ul class='not-need'>    <li>1</li>    <li>2</li>    <li>3</li>    <li>4</li>    <li>5</li>  </ul>

or

$('ul').not('.not-need').find('li').css('color', 'red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <ul>    <li>1</li>    <li>2</li>    <li>3</li>    <li>4</li>    <li>5</li>  </ul>      <ul class='not-need'>    <li>1</li>    <li>2</li>    <li>3</li>    <li>4</li>    <li>5</li>  </ul>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -