I am trying to write line of jquery that finds an input that has a class that begins with “a\d” (the letter a and a number) and replace the number with another number.
This is what I have tried, does anyone notice why this would not work?
$('form').find('input[class^="a\d"]').replace(/a\d+/,'a22');
Please note: this is one line out of many, I have extracted this line because it is where I am having trouble.
You’ll need to do it more like this:
When using
.attr()to set theclass(or any attribute), you can pass it a function which has 2 parameters. Theiis the current index in the iteration. Theclsis the current value ofclass.The
returnvalue will be used to update theclass. If nothing is returned, nothing will be changed.