The method of getting ID by Jquery selector through class name
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.