如何使用class tagit-label为span中的每个标记添加id?我需要添加标签文本作为ID添加到标签。
<ul id="singleFieldTags" class="tagit ui-widget ui-widget-content ui-corner-all">
<li class="tagit-choice ui-widget-content ui-state-default ui-corner-all tagit-choice-editable">
<span class="tagit-label">Others</span>
<a class="tagit-close">
<span class="text-icon">×</span>
<span class="ui-icon ui-icon-close"></span>
</a>
</li>
<li class="tagit-choice ui-widget-content ui-state-default ui-corner-all tagit-choice-editable"><span class="tagit-label">Facebook</span><a class="tagit-close"><span class="text-icon">×</span><span class="ui-icon ui-icon-close"></span></a></li>
<li class="tagit-new"><input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible">1 result is available, use up and down arrow keys to navigate.
</span></li>
</ul>
答案 0 :(得分:0)
试试这个:
$('.tagit-label').each(function(){
$(this).attr('id',$(this).text());
});