Reputation: 237
I am using some Html and jQuery code. I want to get data-name
value from link tag.
Below is my link code that I am using:
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$(this).click(function(){
console.log($(this).data("name"));
});
});
</script>
<a class="dz-cover" href="javascript:undefined;" data-name="cover" data-dz-remove="">Make Cover</a>
When i click on link tag my jquery code is below console.log($(this).data("name"));
but it giving me undefined what i do where i am wrong please help me
Upvotes: 0
Views: 1585
Reputation: 177691
Like this
$(function(){
$(".dz-cover").on("click",function(e){
e.preventDefault();
console.log($(this).data("name"));
});
});
Using
<a class="dz-cover" href="plsenablejs.html" data-name="cover" data-dz-remove="">Make Cover</a>
Upvotes: 1
Reputation: 1084
try the below code
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$(".dz-cover").click(function(){
console.log($(this).attr("data-name"));
});
});
</script>
Upvotes: 0