<p>I am trying to apply styles to HTML tags dynamically by reading in the value of certain HTML attributes and applying a class name based on their values. For instance, if I have:</p>

<pre><code>&lt;p height="30"&gt;
</code></pre>

<p>I want to apply a <code>class="h30"</code> to that paragraph so that I can style it in my style sheet. I can't find any information on getting the value of an attribute that is not an <code>id</code> or <code>class</code>. Help?</p>

[{'answer_id': 53475, 'author': 'Frank Krueger', 'author_id': 338, 'author_profile': 'https://Stackoverflow.com/users/338', 'pm_score': 0, 'selected': False, 'text': '<p>Attributes are just properties (usually). So just try:</p>\n\n<pre><code>for (e in ...) {\n    if (e.height == 30) {\n        e.className = "h30";\n    }\n}\n</code></pre>\n\n<p>Or use something like jquery to simplify this kind of stuff.</p>\n'}, {'answer_id': 53485, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 2, 'selected': False, 'text': '<p>See: <a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-666EE0F9" rel="nofollow noreferrer">getAttribute()</a>. Parameter is the name of the attribute (case insensitive). Return value is the value of the attribute (a string). </p>\n\n<p>Be sure to see the <a href="http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx" rel="nofollow noreferrer">Remarks</a> in MSDN before dealing with IE...</p>\n'}, {'answer_id': 53593, 'author': 'SeanDowney', 'author_id': 5261, 'author_profile': 'https://Stackoverflow.com/users/5261', 'pm_score': 4, 'selected': True, 'text': '<p>I would highly recommend using something like jquery where adding classes is trivial:</p>\n\n<pre><code>$("#someId").addClass("newClass");\n</code></pre>\n\n<p>so in your case:</p>\n\n<pre><code>$("p[height=\'30\']").addClass("h30");\n</code></pre>\n\n<p>so this selects all paragraph tags where the height attribute is 30 and adds the class h30 to it.</p>\n'}, {'answer_id': 324566, 'author': 'Kornel', 'author_id': 27009, 'author_profile': 'https://Stackoverflow.com/users/27009', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s better to separate layout and presentation. </p>\n\n<p>Despite using CSS, you\'re tying these two together. <a href="http://www.w3.org/QA/Tips/goodclassnames" rel="nofollow noreferrer">Use better class names</a> (why does it have to have 30px height? Is it menubar? footer? banner?)</p>\n'}]
['https://Stackoverflow.com/questions/53473', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5512/']