JQuery / Firefox error with textarea and .text?

The 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> 

The behavior for this in Chrome and Firefox is the same, you click "One" or "Two" and change the text box. However, in firefox, if you manually change the contents of a text field, it will no longer be updated when clicked. Chrome continues to work fine.

I am running firefox 3.6.15

Can anyone explain this behavior? I am not sure if I am doing something wrong, or if this is a real mistake. My actual implementation uses the correct markup and $ (document) .ready, etc.

+4
source share
1 answer

You are really right, however, changing them to val() works .

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

val() is probably the more correct method to use.

In addition, I am sure that you know that you should not use the built-in event handlers, except for trivial examples, for example, above.

+7
source

Source: https://habr.com/ru/post/1342797/


All Articles