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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Best practice is to use HTML5
data-*attributes: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.