我已经看到可以将title
属性转移到类。问题是如何找到第一个单词的元素(动画)并将它们分配给类标题?
例如:
<div class="colelem" title="animated infinite bounce"></div>
<div class="colelem" title="animated infinite bounce"></div>
从tittle中添加类
<div class="colelem animated infinite bounce" title="animated infinite bounce"></div>
<div class="colelem animated infinite bounce" title="animated infinite bounce"></div>
答案 0 :(得分:1)
您可以使用.addClass( function )
来完成这项工作。
$(".colelem").addClass(function(){
return $(this).attr("title");
});
&#13;
.animated {
color: red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="colelem" title="animated infinite bounce">A</div>
<div class="colelem" title="animated infinite bounce">B</div>
<div class="colelem" title="animated infinite bounce">C</div>
&#13;