Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of getting ID by Jquery selector through class name

Shulou Source: shulou.com Published: 2022-06-01 07:34:53 10月01日 Update

This article mainly introduces the relevant knowledge of "the method of Jquery selector getting ID through class name". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "Jquery selector gets ID through class name" can help you solve the problem.

Obtained by class name

Press class to find and note that add a.: before the class name:

Vara=$ ('.red'); / / all nodes containing `class= "red" `will be returned.

/ / for example:

/ /...

/ /...

Find objects that contain multiple class names, such as "car" and "bus"

Vara=$ ('.car.bus'); / / Note there are no spaces!

/ / nodes that meet the criteria:

/ /...

/ /...

Get the ID of p through its class name

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

$(".tab-pane.active") .attr ("id")

/ / results that meet the criteria:

One

/ /...

Get the class of p through its ID name

$(".tab-pane.active") .attr ("id")

$("p#hrefMenu0") .attr ("class")

/ / results that meet the criteria:

Tab-panebusactive

/ /...

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

$(".tab-pane.active") .children () .attr ("id") / / get the following two id:content,page

Obtain the ID of the peer node under p through the class name of p

$(".tab-pane.active") .next () .attr ("id") / / get the following id:content

This is the end of the introduction to "how the Jquery selector gets the ID through the class name". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Method node selection condition knowledge at the same time result industry different practical two content sibling name multiple name subset practicality actual object Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Docker Redmi MySQL