If you want to target the elements with multiple classes names, such as selecting the elements only if it has both classA and classB, or has classes classA, classB,...,classX or something like that, just put the class selectors together without any space in between, as shown below:
<!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");
});
</script>
</head>
<body>
<p class="classA">Element with classA (won't match)</p>
<p class="classA classB">Element with classA and classB (match)</p>
<p class="classB">Element with classB (won't match)</p>
<p class="classB classA">Element with classB and classA (match)</p>
<p class="classD">Element with classD (won't match)</p>
<p class="classA classD classB">Element with classA, classD and classB (match)</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to Detect Change in a Text Input Box in jQuery
Use the input Event You can bind the&...Laravel 5 Chart example using Charts Package
Today, we are share with you how to use...PHP - How to get filename from N-level file directories
In this tutorials we are share with you...How to sort an array values alphabetically in PHP
Use the PHP sort() and rs...How To Create Custom Helper In Laravel 5.5
Today in this article we are share with...