修改某个类的所有html [英] modify all html of a certain class
本文介绍了修改某个类的所有html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个
<p class="comment_date" title="a">c</p>
<p class="comment_date" title="b">b</p>
我想将标题放在任何元素的html中.所以我尝试一下:
i want put the title in the html of any element. so i try with this:
$(".comment_date").html($('.comment_date').attr("title"));
但这是错误的
我该怎么做?
谢谢
推荐答案
$('.comment_date').each(function() {
$(this).html( $(this).attr('title') );
});
我认为应该这样做-让我知道这是否不是您想要的东西.
I think this should do it - let me know if that isn't what you're looking for.
检查title
属性长度是否为>0
可能是值得的.最好在这种情况下使用.each
,否则,如果不使用.each
,则会将某些内容设置为多个元素的值的组合值.
It may be worth it to check if the title
attribute length is >0
. It's best to use .each
for cases such as this, otherwise you're setting something to the combined value of multiple elements' values if you don't use .each
.
这篇关于修改某个类的所有html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文