To access data/id from html
in html form let say it's a button, we can put any fields as the data (by putting the tag data-<something>)
<input class="myclass" data-myvalue="myValue123" id="myID" type="button" />
To access the element using ID from the javascript:
$('#myID').click(function(e){
var myvalue = $(this).data('myvalue');
});
To access the element using the class from javascript:
$('.myclass').click(function(e){
var myvalue = $(this).data('myvalue');
var myID = $(this).attr('id');
});
No comments:
Post a Comment