Jquery data attribute value undefined -


html:

<button class="btn btn-sm green btn-outline filter-submit margin-bottom" data-type="invoice generate" onclick="show_modal()"><i class="fa fa-envelope"></i></button> 

jquery:

function show_modal(){     alert($(this).data("type"));     $('#basic').modal('show');  } 

output:

undefined 

expected output:

invoice generate 

anyone can please tell me why alerting undefined , how can resolve it?

you show_modal function don't know $(this) is. add this onclick="show_modal()" onclick="show_modal(this)"

then you, of course, has update function below:

function show_modal(obj){     alert($(obj).data("type"));     $('#basic').modal('show');  } 

function show_modal(obj){      alert($(obj).data("type"));      $('#basic').modal('show');   }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <button class="btn btn-sm green btn-outline filter-submit margin-bottom" data-type="invoice generate" onclick="show_modal(this)"><i class="fa fa-envelope"></i></button>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -