how to create custom attribute for html tag.
Sample HTML Code:
<div class="header" custom-data-attribute="hide"> sample text </div>
how to create custom attribute for html tag.
Sample HTML Code:
<div class="header" custom-data-attribute="hide"> sample text </div>
You can use data-*
HTML5 attribute:
<div class="header" data-custom-attribute="hide"> sample text </div>
then apply .data() to set the value:
$('div.header').data("custom-attribute","value here");
and retrieve the value using:
var customAttr = $('div.header').data("custom-attribute");
Try using .attr()
function,
$('div.header').attr('custom-data-attribute','hide');
You can use .attr()
or .prop()
. Try this:
$('div.header').attr("custom-data-attribute","hide");
or
$('div.header').prop("custom-data-attribute","hide");