PacPac PacPac - 5 months ago 14
jQuery Question

Get the data element value after clicked in jQuery

I have this type of link:

<a href="#" data-module="planning">Planning</a>


If I want to detect the click on this type of link, I use:

$("a[data-module ='*']").click(function() {
alert("clicked");
});


But how can I get the
planning
value ?

Thanks.

Answer

Use jquery attr API :

$("a[data-module ='*']").click(function() {
    var dataModule = $(this).attr('data-module');
});