views:

72

answers:

3

Hi, I am trying to select specific element types in a row and change their attribute, specifically the id and name attributes.

Using the following works fine for single line text input boxes:

$('input:text', newRow).attr('id','os' + newRowNum ).attr('name','os' + newRowNum );

however, when I change the html to:

<td><textarea name="os2" cols="24" rows="3" id="os2"></textarea></td>

the script will no longer find the attributes and change them. A textarea is an input element ... no?

I have also tried:

$('input:text, textbox', newRow).attr('id','os' + newRowNum ).attr('name','os' + newRowNum );

and

$('input[type=text], textbox', newRow).attr('id','os' + newRowNum ).attr('name','os' + newRowNum );

but neither work.

What am I missing here?

Dave

+1  A: 

<textarea> elements do not match the :text selector.

This doesn't work because it's <textarea> not <textbox>.

$('input:text, textbox', newRow)

So this should work:

$(":text, textarea", newRow)...
cletus
Does not work. It seems that it has to be 'textarea' only, as Michael said in the precious response.
Dave
+2  A: 

You need to change the selector to:

$('textarea', newRow).attr('id','os' + newRowNum ).attr('name','os' + newRowNum );
Michael Edwards
Crap ... yes this works just fine. I swear I thought I had tried that. But, a textarea is a text input box yes? Just curious why that would not work?
Dave
a text box isn't an input box in the same way, essentially the select "input:text" is short hand for "input[type='text']" and since a textarea is not an input element it would never match
Michael Edwards
A: 

Not exactly.

  $('input:text')

will specifically look for <input> tags.

You may need to consider:

 $('textarea') ...
Vincent Ramdhanie
Yeah I got that from Michaels' post. Thanks
Dave