I want to set attributes to tag without jQuery.
I have to set this dynamically.
I understand in jQuery you just do $(‘html’) but without jQuery, I tried Document.getElementById('html') but does not work.
How can I do this?
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.
In the general case, the standard DOM equivalent to
jQuery('element_name');isdocument.getElementsByTagName('element_name');. Note that it returns a NodeList (which is like an array) and not just an HTMLElementNode.The HTML element, as the root element, can be accessed via
document.documentElement.Setting attribute values can be done with the
setAttribute('attribute_name', 'attribute_value');method on an HTMLElementNode. The method is buggy in older versions of Internet Explorer, so you may wish to use the equivalent DOM property instead.For example, to replace the value of the
classattribute: