Append a string to the end of an element attribute using jQuery

Posted by ILMV on Stack Overflow See other posts from Stack Overflow or by ILMV
Published on 2010-03-25T13:54:58Z Indexed on 2010/03/25 14:03 UTC
Read the original article Hit count: 335

Filed under:
|

I have an element:

<select id="row" />

I want to append a string to the end of the id attribute, like this:

<select id="row_1" />

The jQuery I am using to achieve this is (from within an each):

$(this).attr('id',$(this).attr('id')+'_'+row_count);

This looks ugly as sin, and whilst it works I want to know if there is a simpler solution. In this example, the ID prefix (e.g. row) is never constant, so I can't just do 'row_'+row_count.

Cheers!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about append-string