jQuery <li> Highlight li elements only inside the ul element with id mark

Description

jQuery <li> Highlight li elements only inside the ul element with id mark

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Select Element by Compound Selector</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    // Highlight li elements only inside the ul element with id mark
    $("ul#mark li").css("background", "red");

});//from  w  w w. j  a v a 2s .  c o  m
</script>
</head>
<body>
    <p>This is a paragraph.</p>
    <p class="mark">This is another paragraph.</p>
    <p>This is one more paragraph.</p>
    <ul>
        <li>List item one</li>
        <li>List item two</li>
        <li>List item three</li>
    </ul>
    <ul id="mark">
        <li>List item one</li>
        <li>List <span>item two</span></li>
        <li>List item three</li>
    </ul>
    <ul class="mark">
        <li>List item one</li>
        <li>List item two</li>
        <li>List item three</li>
    </ul>
    <p>Go to <a href="http://java2s.com/" target="_blank">Home page</a></p>
</body>
</html>



PreviousNext

Related