NibblyPig
NibblyPig

Reputation: 52942

JQuery/Firefox bug with textarea and .text?

Code can be tested here: http://jsfiddle.net/yWUTK/3/

<textarea id='textbox'></textarea>

<span onclick="$('#textbox').text('One');">One</span>
<span onclick="$('#textbox').text('Two');">Two</span>

Behaviour for this in Chrome and Firefox is the same, you click One or Two and it changes the textarea. However, on firefox, if you then manually change the content of the textarea, it no longer updates when you click. Chrome continues to work fine.

I'm running firefox 3.6.15

Can anyone explain this behaviour? I'm not sure if I am doing something wrong, or if it's a genuine bug. My actual implementation uses proper markup and $(document).ready etc.

Upvotes: 4

Views: 2563

Answers (1)

alex
alex

Reputation: 490233

You are indeed correct, however, changing them to val() works.

<span onclick="$('#textbox').val('One');">One</span>
<span onclick="$('#textbox').val('Two');">Two</span>

val() is arguably the more correct method to use as well.

Also, I'm sure you are aware, you shouldn't use inline event handlers except in trivial examples like above.

Upvotes: 7

Related Questions