This article mainly shares with you the Jquery selector to obtain ID instances through class names. I hope it can help everyone.
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>
Find objects that contain multiple class names at the same time, such as "car" ” and “ bus”
var a = $('.car.bus'); // 注意没有空格! // 符合条件的节点: // <p class="car bus">...</p> // <p class="blue bus car">...</p>
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>
$(".tab-pane.active").attr("id") $("p #hrefMenu0").attr("class") // 符合条件的结果: tab-pane bus active // <p class="tab-pane bus active" id="hrefMenu0">...</p>
$(".tab-pane.active").children().attr("id")// 获取到以下两个id:content,page<p class="tab-pane active"> <p id="content"></p> <ul id="page"></ul> </p>
$(".tab-pane.active").next().attr("id")// 获取到以下id:content<p class="tab-pane active"> </p> <p id="content"></p>
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!