Home > Web Front-end > JS Tutorial > body text

jquery multiple selector for selecting multiple elements

高洛峰
Release: 2016-12-17 16:04:27
Original
1317 people have browsed it

In jQuery, you can select multiple selections by separating characters with commas.

For example:

$(.class1, .class2, #id1)

In the above example, all elements with class name class1, class2 and id 1 will be selected.

Jquery example:

In the following example, all elements with class name p1 and class name p2 and id div3 will dynamically add a red border.

<html>  
<head>  
<title>select mutiple elements example</title>  
<script type="text/javascript" src="../jquery-1.11.1.min.js"></script>  
</head>  
<script type="text/javascript">  
$(document).ready(function(){  
$(".p1,.p3,#div3").css("border","2px solid red");  
  
  
  
});  
  
  
</script>  
<body>  
<h1>select mutiple element example</h1>  
<p class="p1">P1</p>  
<p class="p2">P2</p>  
<p class="p3">P3</p>  
<p class="p4">P4</p>  
   
<div id="div1">DIV1</div>  
<div id="div2">DI2</div>  
<div id="div3">DI2</div>  
<div id="div4">DI2</div>  
</body>  
</html>
Copy after login

Effect:

jquery 用于选择多个元素的多选择器


For more jquery multi-selector related articles for selecting multiple elements, please pay attention to the PHP Chinese website!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!