[jQuery] Re: Attribute renaming

2007-09-26 Thread voltron
I am trying to rename the ids and name attributes On Sep 26, 10:06 am, Erik Beeson [EMAIL PROTECTED] wrote: What are you trying to accomplish? --Erik On 9/26/07, voltron [EMAIL PROTECTED] wrote: I have tags like this: select id=academic_from_month-0 select id=academic_till_month-0

[jQuery] Re: Attribute renaming

2007-09-26 Thread Erik Beeson
Rename them from what to what? To change the id of all selects, you can do: $('select').each(function() { var oldId = $(this).attr('id'); $(this).attr('id', oldId.substring(0, oldId.lastIndexOf('-'))); }); I'm still not sure what you actually want to do though. --Erik On 9/26/07, voltron

[jQuery] Re: Attribute renaming

2007-09-26 Thread voltron
Hi Erik, I am cloning a DIV container full of elements( selects, inputs and buttons), they all inherit the name of the original element, but to differentiate between all, I want to rename all the clones attributes sequentially, example div name= container input name=color input name=house /dv

[jQuery] Re: Attribute renaming

2007-09-26 Thread Erik Beeson
How about something like (untested): $('#container').clone().attr('id', 'container'+idx).find('*').each(function() { this.name += idx; this.id += idx }).end().appendTo(...); How you deal with 'idx' is up to you. So that's: select the element with ID 'container', clone it, update the clone's

[jQuery] Re: Attribute renaming

2007-09-26 Thread [EMAIL PROTECTED]
I have tags like this: select id=academic_from_month-0 select id=academic_till_month-0 since the ids are variable in length, I would have to find out where the lastindex() of - is remove that and replace it it with the new value. My problem is the syntax, is there some kind of Jquery way

[jQuery] Re: Attribute renaming

2007-09-26 Thread voltron
Thanks guys, I used a mixture of both your suggestions: var ident = String(this.name); changed= ident.substring(0 ,ident.lastIndexOf('-')+1) + suffix; $(this).removeAttr(id); $(this).removeAttr(name); this.name += changed; this.id += changed; $(this).attr(clone, changed); On Sep 26, 11:06