I'm trying to construct a jQuery selector to select both a h1 that contains a certain word and then find the button that's accompanied by the h1.
This is the HTML structure that I can't change.
<div class="item1">
<h1>Title</h1>
<div id="cctrl">
<form>
<input>
<input>
<fieldset>
<input class="button" type="submit" value="submit">
</fieldset>
</form>
</div>
I'm trying to select the submit button on basis of the h1 title. So for example: If h1 title is John, I want to find the button that has that exact h1 title near it and click it.
To do this I tried to use an .each() method.
$("h1:contains('John')>.button[value='submit']").each(function(){
$(this).click();
});
If more buttons with the h1 title John exist, I want to each method to click all of them. But my jQuery isn't working how I want it to and I'm stuck right now. Does anyone know how to fix this?