Select all LI elements for a UL element and add class to all of them in jQuery
Description
The following code shows how to select all LI elements for a UL element and add class to all of them.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type='text/javascript'>
var tmpExample = {
ready : function() {<!-- ww w . j av a2s.co m-->
$('ul').children().addClass('tmpChild');
}
};
$(document).ready(tmpExample.ready);
</script>
<style type='text/css'>
li.tmpChild {
background: #cf0c35;
color: white;
}
</style>
</head>
<body>
<ul>
<li>java 2s.com</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
</ul>
</body>
</html>