> $(function(){
>
> $("div.OrderEntryListRow").not(".Selected").each(function(i){
> alert("before: " + $(this).attr("id"));
> $(this).attr("id", "Row_" + (i+1));
> $(this).html($(this).html() + ': ' + (i+1));
> alert("after: " + $(this).attr("id"));
> });
>
> });
Any time you see that much repetition in a piece of code, you should think,
"That might be expensive - let's do it once instead of many times."
So the first response would be to call $(this) only once:
$("div.OrderEntryListRow").not(".Selected").each(function(i){
var $this = $(this);
alert( "before: " + $this.attr("id") );
$this.attr( "id", "Row_" + (i+1) );
$this.html( $this.html() + ': ' + (i+1) );
alert( "after: " + $this.attr("id") );
});
But we can do even better here. There's no reason to use .attr() and .html()
at all:
$("div.OrderEntryListRow").not(".Selected").each(function(i){
alert( "before: " + this.id );
this.id = "Row_" + (i+1);
this.innerHTML += ': ' + (i+1);
alert( "after: " + this.id );
});
That is both faster and much simpler.
-Mike
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/