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
Post a Comment