javascript - How to add data to the anchor tag in HTML and access it using jQuery? -
following html code of anchor tag:
<a delhref="http://localhost/eprime/entprm/web/control/modules/questions/manage_question_issue.php?op=fixed&question_id=21627&que_issue_status=0" title="fixed" href="#fixedpopcontent" class="fixed">fixed</a> now want add question id above anchor tag , access in jquery when user clicks on hyperlink. tried below code didn't work out me.
<a delhref="http://localhost/eprime/entprm/web/control/modules/questions/manage_question_issue.php?op=fixed&question_id=21627&que_issue_status=0" title="fixed" href="#fixedpopcontent" class="fixed" data="21627">fixed</a> the jquery code follows:
$(document).ready(function() { $(".fixed").click(function(e) { var t2 = $(this).data(); alert(t2); }); }); it's giving me message [object object] in alert box. can please me in setting value anchor tag , accessing in jquery?
try this
html
<a href="#fixedpopcontent" class="fixed" data-q_id="21627"></a> javascript
$(document).ready(function() { $(".fixed").click(function(e) { var t2 = $(this).data('q_id'); alert(t2); }); }); you can add attribute data-sample_name on html element. in jquery use
$('your_element_id').data('sample_name');// value $('your_element_id').data('sample_name','new value');// set value
Comments
Post a Comment