简体   繁体   中英

Jquery select button by name

I don't understand how to select by name with Jquery the button "g_list".

<div class="col-sm-4 sezione-na">
<div class="titolo-sezione-na">Title:</div>
<div class="form-group">
    <div class="col-sm-12"><button name="g_list" type="button" class="btn btn-primary btn-block">Generate list</button></div>
</div>

I wrote this Jquery code, but it doesn't work:

$("input[name='g_list']").click(function(){
alert( "ready!" );});

In your code input[name='g_list'] will be search input element with that name, instead you need to search for button so use button[name='g_list'] for that.

 $("button[name='g_list']").click(function() { //--^------ change here alert("ready!"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="col-sm-4 sezione-na"> <div class="titolo-sezione-na">Title:</div> <div class="form-group"> <div class="col-sm-12"> <button name="g_list" type="button" class="btn btn-primary btn-block">Generate list</button> </div> </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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM