有很多div.post
。我需要从中选择一个。。。具有CCD_ 2的那一个。然后在<!-- Here! -->
位置添加新标签。知道吗?
FireBug说parent((不是函数。。。jQuery 1.6.1。
<div class="post">
<div class="post_head"><div> </div></div>
<div class="post_body">
<!-- ... -->
<div class="options">
<a class="gray_button comment_this" href="#" rel="123">Comments</a>
<span class="gray_txt">0 comments</span>
</div>
<!-- Here! -->
</div>
<div class="post_bottom"><div> </div></div>
</div>
这就是我所拥有的。。。
$('.post .comment_this').attr('rel').parent().html('foo');
要选择具有属性的元素,请使用has属性选择器[name]
。attr
返回属性的值,而不是通过它进行过滤。显然,字符串(如"123"
(没有parent
方法!
您可能还需要after
,而不是html
,这样就不会覆盖所需的内容。
$('.comment_this[rel]').parent().after('your html');
$('.comment_this[rel] ').parent().after('foo');
这是jsfiddle