I'm looking for the right jquery selector to find the
<form> element that contains a particular element located by class. Not quite sure how to do this. What I mean is, I want to be able to select the containing form for an element, sort of like what:
might do for the following HTML. That's not a real locator obviously, but hopefully it's legible to see what I'm going for.
<form> <input type='text'></input> <input type='button' class='submitbutton1'> </form> <form> <input type='text'></input> <input type='button' class='submitbutton2'> </form>
How would I get the containing form with ".submitbutton1" as a starting point?
hmm, I see that :
actually works well.
There is a good way to get to the form from your selector button using
mamal's answer is perfect for your requirement (+1 for that answer). I am just curious to know why do you need such an implementation where the form is distinguished by an child elemen's css class?
Isn't the following more specific and semantically more correct? I might be wrong, but can't help asking. :)
<form> <input type='text'></input> <input type='button' id='submitbutton1' class='buttonClass1'> </form> <form> <input type='text'></input> <input type='button' id='submitbutton2' class='buttonClass2'> </form>