I've been adding custom attributes which I reference using JQuery, this works great. But is it good practice?
example:
<div class="monkeys" customattr="big Monkey"> </div>
thanks all
Best practice is to use HTML5 data-*
attributes:
<div class="monkeys" data-customattr="big Monkey"> </div>
This is standards-compliant HTML5, unlike arbitrary custom attributes. It also makes sure that your custom attribute won't conflict with some future standard attribute.
In recent (1.5+) versions of jQuery, you can also use $('.monkeys').data('customatrr')
to access the attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With