Alternatively, you can also use the jQuery data() method (jQuery version >= 1.4.3), to get the data-attribute of an element using the syntax like $(element).data(key).
That means in the above example to get the data-id using data() method you can use the statement like $(this).data("id"). Key is the rest of the part after removing data-.
Use the jQuery
attr()MethodYou can simply use the jQuery
attr()method to find thedata-idattribute of an HTML element.The following example will show you how to get the data-id of the clicked item.
Alternatively, you can also use the jQuery data() method (jQuery version >= 1.4.3), to get the data-attribute of an element using the syntax like $(element).data(key).
That means in the above example to get the data-id using data() method you can use the statement like $(this).data("id"). Key is the rest of the part after removing data-.
need an explanation for this answer? contact us directly to get an explanation for this answer