× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

jQuery .data() and .attr() method

Foysal
Nov 17, 2014
<p>if you set data attribute on an element using the jQuery.attr() method make sure you retreive it using using the same .attr() method. </p><p> </p><pre><code class="language-javascript">jQuery('#random-element').attr('data-test', 'testData'); // **NOT reliable jQuery('#random-element').data('test'); // **Use this instead jQuery('#random-element').attr('data-test'); </code></pre><p> </p>
comments powered by Disqus