jQuery group selector method example
- 2020-05-07 19:16:07
- OfStack
An example of jQuery group selector is presented. Share with you for your reference. Specific analysis is as follows:
The group selector returns 1 from merging the elements to which each selector matches and can perform the same operation on them.
Example code:
$(".mydiv ,span")
The above code matches the element of the class named mydiv with all span elements. The two selectors are separated by commas.
Example code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<style type="text/css">
div{
height:150px;
width:150px;
background-color:green;
margin-top:10px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$(".mydiv ,span").css("color","red");
})
})
</script>
</head>
<body>
<div class="mydiv"> The home of the script </div>
<span> Welcome to script house </span>
<button> Click to view </button>
</body>
</html>
The code above can set the font color in div and span with the class mydiv to red.
I hope this article has been helpful to your jQuery programming.