I have multiple form input elements. I would like to add a pattern
attribute and a title
attribute to each one, but rather than do so manually, I
In the end, I found that the syntax was correct. There was an error somewhere else in the code preventing that statement from being run. Just goes to show that you should always make sure everything is good elsewhere in your code first.
However, I did learn a few things from this which I will note for others:
.attr()
function will dynamically add any attribute you specify, so you don't need to put pattern=""
in your form elements first in order for the value to be added or changed.The regex was originally \d*\.?\d*
but in the DOM it was showing up as d*.?d*
so when sending the regex through jQuery I escaped the backslashes like so: \\d*\\.?\\d*
.