custom-attribute

custom attribute works only with element.getAttribute(“attribute”) but not “element.attribute”

我与影子孤独终老i 提交于 2019-11-27 03:25:50
问题 I have just noticed, that if I give a custom attribute to an html element, for example: <input type="button" id="my_button" custom_attr="custom_attr_text" value="value_text" /> then i can retrieve it like this: document.getElementById("my_button").getAttribute("custom_attr"); and it will return "custom_attr_text" , but if I do document.getElementById("my_button").custom_attr; then it returns undefined ! I also noticed that with a built in attribute (for example value or id ) both of the above

Custom attributes - Yea or nay?

心不动则不痛 提交于 2019-11-25 22:29:12
问题 Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in javascript code. I was hoping to gather some feedback on whether or not using custom attributes is a good practice, and also what some alternatives are. It seems like it can really simplify both server side and client side code, but it also isn\'t W3C compliant. Should we be making use of custom HTML attributes in our web