如何用Jquery获取某一个Div的Class或者ID
展开全部
<!--HTML样式-->
<div class="comment" id="22">
<div class="comment_detail" style="display: block; ">
<div class="comment_my"><textarea class="comment_text" style="height: 16px; "></textarea></div>
<div class="comment_text_bottom" style="display: none; ">
<div class="comment_emotion"><a href="javascript:void(0)" class="comment_emotion_button">表情</a>
<div class="comment_emotion_detail" style="display: none; ">
</div>
</div>
<div class="comment_publish"><input class="submit" type="submit" value="评论"></div>
</div>
</div>
<div class="comment_bar"><a href="javascript:void(0)" class="comment_click"></a></div>
</div>
如果从submit处定位,获取到comment处DIv的ID,那么我就可以这样办:
ID值为:
$(".submit").parent().parent().parent().parent().attr('id');
//其值为:22;
CLASS值为:
$(".submit").parent().parent().parent().parent().attr('class')
//其值为:comment;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询