I want to create a new element with html5 data attributes defined, however they are not showing in the DOM (unlike when using say .addClass). is this intended behavior?
this creates an element without the data-foo attributs:
-> $("<div>foo</div>").data('foo', 'bar').addClass('class')
=> <div class="class">foo</div>
i had to declare it in the constructor
-> $("<div data-foo='bar'>foo</div>").addClass('class')
=> <div class="class" data-foo="bar">foo</div>
shouldn’t the .data method work do the same?
From here:
So, use the usual
attr…