I have a button
<button type="button" data-id="5" class="get_attr" >Click Me</button>
and i want to get the data-id value then i write the code
<script type="text/javascript">
$(".get_attr").on("click",function(){
var id = $(this).data("id");
console.log("id = "+id); //id = 5
});
</script>
Suppose I want this value, or do any functionality on this button
from another function
if i call function
from this code like and I want like this:
<script type="text/javascript">
$(".get_attr").on("click",function(){
updateValue(this);
});
function updateValue(this){ // it will take it as a parameter
var id = $(this).data("id");
console.log("id = "+id); //id = 5
}
</script>