Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!" );});
like image 628
Fabio Avatar asked May 30 '16 15:05

Fabio


1 Answers

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>
like image 92
Pranav C Balan Avatar answered Oct 04 '22 08:10

Pranav C Balan