There is a div, and I want to get its ID or class value.
So I can navigate to the div and take the attr method to get its value:
If you say: There is a section of HTML code:
| The code is as follows |
Copy Code |
<div class= "comment" id= ">" <div class= "Comment_detail" style= "display:block; "> <div class= "comment_my" ><textarea class= "Comment_text" style=; "></textarea></div> <div class= "Comment_text_bottom" style= "display:none; "> <div class= "comment_emotion" ><a href= "javascript:void (0)" class= "Comment_emotion_button" > Www.111cn.net Facial Expression </a> <div class= "Comment_emotion_detail" style= "display:none; "> </div> </div> <div class= "Comment_publish" ><input class= "Submit" type= "submit" value= "comments" ></div> </div> </div> <div class= "Comment_bar" ><a href= "javascript:void (0)" class= "Comment_click" ></a></div> </div> |
If I want to locate from submit and get the ID of the div at comment, then I can do this:
The ID value is:
| The code is as follows |
Copy Code |
$ (". Submit"). Parent (). Parent (). Parent (). attr (' id ');
|
The value is: 22;
The class value is:
| The code is as follows |
Copy Code |
$ (". Submit"). Parent (). Parent (). Parent (). attr (' class ') |
The value is:
Comment
Gets the class value and sets the
| The code is as follows |
Copy Code |
<div class= "div" > <span class= "Span" ></span> <a href= "javascrip:void (0)" class= "a" >
</a> </div> $ ("Div.div"). Hover (function () { $ (this). Next ("Span.span"). Show (); },function () { $ (this). Next ("Span.span"). Hide (); }); |
If you want to take a property value of a class element, we just
| The code is as follows |
Copy Code |
| $ (". Foo"). Click (function () {Alert ($ (this). attr ("value")); |
You can write it.