I am trying to make it so my JQuery auto clicks the next button if the button is pressed. On the internet I found that should be like this (look at JQuery section). But for some reason it doesn't work.
Do they have to be in the same <div>
in order to work like that?
What I have tried: JQuery:
<script type="text/javascript">
$(document).ready(function(){
$("#sobmit").bind("click", (function () {
}));
$("#submit").bind("click", (function () {
$("#sobmit").trigger("click");
}));
});
</script>
Button 1 in a form
html:
<input type="submit" id="sobmit" name="sobmit" value="sobmit" placeholder="sobmit" />
Button 2 in a form
html:
<input type="submit" id="submit" value="Add to Cart" class="btnAddAction" /></div>
$(document).on('click', '#submit', function(){ $("#sobmit").trigger("click"); console.log("#sobmit button get clicked by trigger"); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Button 1 <input type="submit" id="sobmit" name="sobmit" value="sobmit" placeholder="sobmit" /> <br><br> Button 2 <input type="submit" id="submit" value="Add to Cart" class="btnAddAction" /></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.