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')
.
精彩评论