JQuery maxlength attribute problem with text fields

With jQuery version 1.2.3, I am trying to add nodes after textarea elements with the attribute 'maxlength', but this does not work:

$("textarea[@maxlength]").after("<b>Aint working</b>");

This is the HTML code:

<textarea maxlength="500">This is a test.</textarea>
<textarea maxlength="250">Yet another line.</textarea>
<textarea maxlength="125">Bar or foo, whatever.</textarea>

The odd thing is if I change the maxlength attribute, for example. rel than works just fine!

See an example of real life: http://www.host2000.be/_temp/jquery_tests_counter.html

PS: I know the [@attribute] notation, which is no longer supported in jQuery 1.3, but this has nothing to do with the problem.

+4
source share
2 answers

With your jQuery version, it only works with a little trick. Implicit value textarea has different meanings for different browsers. Firefox, for example, has an implicit value of -1. A.

So for your script to work in Firefox, you need to do the following:

 $("textarea[@maxlength!=-1]").after("<b>Aint working</b>"); 

Here you can find more information about the implicit values โ€‹โ€‹of the maxlength attribute.

Enjoy it!

+3
source

Shot in the dark: perhaps because maxlength is not a valid attribute for text areas .

EDIT: I just tried your jQuery 1.3 example and removed @ and it worked flawlessly.

EDIT # 2: Using jQuery 1.2.6 also works without @ ... Have you tried removing them?

+3
source

All Articles