I have a page full of divs that contain 1 button each which submit to do a certain function successfully.
However I am currently trying to isolate the buttons by an ID and trigger the addition of a class and message to 2 spots within the div (input value & the #msgsC).
However, the event is not triggering at all. And I think I may be missing something. How can I get it to change/add the class and message to only the sibling input tag and #msgsC of the particular button that is clicked (AND not to all of the inputs in all the divs on the page simultaneously)?
<form id="Hello" target="somePlace" action="#" method="post">
<table>
<tr>
<td>
<select name="os0">
<option value="item1">item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
<option value="item1">item4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="on1" value="Send My URL"/>Send My URL
</td>
</tr>
<tr>
<td>
<input type="text" value="http://" name="os1" id="os1" maxlength="200"/>
</td>
</tr>
</table>
<button alt="Click the button" id="purchase1" name="submit" class="btn" type="image">Add To Cart</button>
</form>
$(document).ready(function () {
$('#purchase1, #purchase2, #purchase3').on('click', 'button', function (e) {
var urlGo = new Array(url1, url2, url3);
for (var x = 0; x < urlGo.length; x++) {
if (!/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(urlGo[x].val())) {
$(this).siblings("input[type=text]").addClass("errorAlert");
$(this).siblings("input[type=text]").val(emptyerror);
$(this).siblings("#msgsC").addClass("text-error");
$(this).siblings("#msgsC").html(htmlEmpty);
} //end of if
} //end of for
}); // end of purchase button function
}); // end document ready