I have a site with mutliple forms, and I would like to, for a specific form, loop through and manipulate the classes on divs and inputs.
I can get the form id with –
var thisForm = $(el).closest('form');
var myId = thisForm[0].id
But then I am not sure how to loop through specific classes.
Example:
for each input with “class1” I want to change it to “class2“
and
for each div with “class3” I want to add “class4“
Any help would be greatly appreciated.
Should be as simple as this
See this example http://jsfiddle.net/dXrN8/2
It’s jQuery, so you don’t need to loop to do these things, actions happen on everything your selector matches.
What we are doing is finding the form, and assigning it to
thisForm.Then use that to scope our selectors in the next two lines.
Then select all
input.class1elements and remove class1 and add class2.Then select all our
div.class3elements and add class4.