jQuery Selector .class select an element with multiple classes

Description

jQuery Selector .class select an element with multiple classes

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Selecting Elements with Multiple Classes</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        // Apply background color to the elements if it has both classA and classB
        $(".classA.classB").css("background-color", "yellow");
    });//  w w w.  j a  v a  2 s  .  co m
</script>
</head>
<body>
    <p class="classA">Element with classA</p>
    <p class="classA classB">Element with classA and classB</p>
    <p class="classB">Element with classB</p>
    <p class="classB classA">Element with classB and classA</p>
    <p class="classD">Element with classD </p>
    <p class="classA classD classB">Element with classA, classD and classB</p>
</body>
</html>



PreviousNext

Related