> i want to know a way to general unique id for new append element. like
> EXT's  .id();

You could use this little plugin--untested:

jQuery.fn.uniqueId = function(suffix, clobber) {
  if ( suffix == null )
    suffix = "UniqueId";
  return this.each(function(){
    if ( !this.id || clobber )
      this.id = "n"+ (++jQuery.fn.uniqueId.index) + suffix;
  });
};
jQuery.fn.uniqueid.index = 0;

It would be chained like this:

$("<div>this div will get an id</
div>").uniqueId().appendTo("#someplace");

I am thinking you must want to save the ID somewhere before you let go
of the new content, so you could continue the chain to something like
this:

var newid = $("<div>this div will get an id</div>")
    .uniqueId().appendTo("#someplace").attr("id");

Reply via email to