根据第一个子文本内容设置范围的标题

时间:2013-03-18 11:35:04

标签: jquery children

我试过了:

$('span.tag').each(function(){
    $(this).attr('title', '').prop('title', function(){$(this).children('li:first').text();});
});

2 个答案:

答案 0 :(得分:1)

为什么这么复杂?这很简单

$('span.tag').each(function(){
    $(this).attr('title', $(this).find('li:first').text());
});

答案 1 :(得分:1)

试试这个:

$('span.tag').attr('title', function(){
    return $(this).find('li:first').text();
});