0

I have the following textarea:

<textarea cols="50" rows="4" id="textbox" onkeyup="limitArea(this, 255, '')"></textarea>

What i need it the onkeyup function to instead read onkeyup="limitArea(this, 150, '')" -- the problem is, I can't edit this part of the code directly.

I tried this with no success:

$('textarea[onkeyup="limitArea(this, 255, \'\')"]').attr('onkeyup', 'limitArea(this, 255, \'\')');

Any other ideas?

3
  • I noticed your textarea has an ID...why not select it with $("#textbox") Commented Mar 27, 2013 at 21:47
  • The jQuery works, but I must be going blind, cause it does'nt look like you are changing anything to me? The inline handler is exactly the same both places. See this FIDDLE, and inspect the elements, and you'll see it's changed ! Commented Mar 27, 2013 at 21:47
  • $("#textbox").on('keyup', ...); Commented Mar 27, 2013 at 21:47

1 Answer 1

3

You need to actually change something, and not just give it the same value :

$(function() {
    $('textarea[onkeyup="limitArea(this, 255, \'\')"]')
                .attr('onkeyup', 'limitArea(this, 150, \'\')');
});                                     //changed ^^^^

FIDDLE

As ID's are unique, it would be a lot easier to target the element with the ID:

$('#textbox')
Sign up to request clarification or add additional context in comments.

1 Comment

Oddly enough, in the code I was playing with it wasn't working and it was the same as yours (I thought -- and yes, I had 150 in mine). But, I posted this, came back, and tried again with yours and lo and behold it starts working. But, oh well, working code is working code. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.