Jquery selector gets ID instance sharing through class name

小云云
Release: 2018-02-28 11:23:01
Original
2454 people have browsed it

This article mainly shares with you the Jquery selector to obtain ID instances through class names. I hope it can help everyone.

Get by class name

To search by class, please add a . before the class name:

var a = $('.red'); // 所有节点包含 `class="red"` 都将返回
// 例如:
// <p class="red">...</p>
// <p class="green red">...</p>
Copy after login

Find objects that contain multiple class names at the same time, such as "car" ” and “ bus”

var a = $(&#39;.car.bus&#39;); // 注意没有空格!
// 符合条件的节点:
// <p class="car bus">...</p>
// <p class="blue bus car">...</p>
Copy after login

Get the ID of p through p’s class name

Sometimes we only know that p’s class name contains one of the names and want to get its id.

$(".tab-pane.active").attr("id")
// 符合条件的结果:
one
// <p class="tab-pane bus active" id="one">...</p>
Copy after login

Get the class of p through the ID name of p

$(".tab-pane.active").attr("id")
$("p #hrefMenu0").attr("class")
// 符合条件的结果:
tab-pane bus active
// <p class="tab-pane bus active" id="hrefMenu0">...</p>
Copy after login

Get the ID of the subset node under p through the class name of p

$(".tab-pane.active").children().attr("id")// 获取到以下两个id:content,page<p class="tab-pane active">
      <p id="content"></p>
      <ul id="page"></ul>
</p>
Copy after login

Get the class name of p Get the ID of the peer node under the p

$(".tab-pane.active").next().attr("id")// 获取到以下id:content<p class="tab-pane active">
</p>
 <p id="content"></p>
Copy after login

Related recommendations:

Detailed explanation of how to handle special symbols in the jQuery selector

Detailed explanation of jquery selector practice

jQuery selector sharing examples of attribute filter selectors

The above is the detailed content of Jquery selector gets ID instance sharing through class name. For more information, please follow other related articles on 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!