Trying to get attribute value with jQuery, then append it to element with class
<div id="data" class="democlass" data-author="Mr. Jhon Doe" data-cat="Technology" data-url="https://google.com"></div>
<p class="data-author"></p>
<p class="data-cat"></p>
<a href="#"></a>
$("#data").each(function() {
var author = $(this).attr("data-author");
var cat = $(this).attr("data-cat");
});
$( document ).ready(function() {
$( ".data-author" ).append(author);
$( ".data-cat" ).append(cat);
});
Am I doing something wrong in the code? here is the sample codepen
eachonidattribute ? and i didn't find more than one div to use each loop ?$.data()a chance.