I want to add a data-attribute to an element and dynamically give it the same value as the class name.
I have used this script to do the same from an elements´string - but I want to pass the value from the class name instead, and not sure how to do that.
Script:
$('.newgroup').attr('data-price', function() {
var text = $(this).text();
return parseInt(text, 10);
});
HTML
<div class="newgroup">/div>
Should looks like this:
<div class="newgroup" data-price="newgroup">>/div>

$(".newgroup").attr("data-price", "newgroup")I think this will be enough for you.