I have the following HTML code and I'm trying to make a JavaScript to click on this button
<fieldset class="fields1"></fieldset>
<fieldset class="submit-buttons">
<some other button here >
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f"></input>
I tried the following lines of code neither of which works:
$(".submit-buttons").children('input[name="post"]').click();
$("input[name=post]").click();
Is there any other way to click the button1? And is there a way to select the button by its tabindex or accesskey?
The click function is for event handling not triggering events. If you want to trigger a click use trigger
$("input[name=post]").trigger('click');
You forgot the close the <fieldset>
tag
Use following markup
<fieldset class="fields1"></fieldset>
<fieldset class="submit-buttons">
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f">
</fieldset>
Also, you would need to add a event handler
callback inside click function
$(".submit-buttons").children('input[name="post"]').click(function(){
alert("clicked")
});
and trigger the click event either manually or by jQuery's trigger()
$("input[name=post]").trigger('click')
here's the demo
First link up any jQuery version and then like
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
$("input[name=post]").click(function(){
alert('dddd');
});
if onready click
$("input[name=post]").trigger('click');
<form action="#" method="post">
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f"></input>
</form>
start <form> end </form>
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.