开发者

How to copy contents of a span into its title attribute?

I have this code now

var i,
$spanc = jQuery("#menu").find("span").filter(":not(.stepnumber)");
        for(i in $spanc){
            $spanc.eq(i).attr("title", $spanc.eq(i).text());
         }

is there a way I can make it simpler开发者_运维问答? Thanks for any suggestion or help


Yep:

jQuery("#menu span:not(.stepnumber)").each(function() {
    $(this).attr('title', $(this).text());
});

You can use .each() to iterate over a jQuery collection. this refers to the current object in the loop. You can also combine selectors into one string, $('#menu span') is the same thing as $('#menu').find('span').

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜