title: How to find html nodes via javaScript
body: <p>I am not an html or javaScript programmer, and as such, I have a question in regards to finding html nodes via javaScript?</p>
  
  <p>I am currently deciding on whether to use class attributes or data attributes for each html node and am not sure if there is a standard practice on how to find html nodes via javaScript?</p>
  
  <p>Here is the situation:</p>
  
  <p>I have x amount of html nodes that need to be found via javaScript. These html nodes are sometimes found by more than one javaScript function, and need to be identified with different attributes for this purpose. So, I am saying that one html node needs to have more than one attribute in some situations, and the same attribute (or equivalent) needs to be used across multiple html nodes in some situations.</p>
  
  <p>Because of the above, I am thinking that using class attributes is correct.</p>
  
  <p>Here is an example:</p>
  
  <p>Html node 1:</p>
  
  <pre><code>&lt;div class="attribute-1 attribute-2"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Html node 2:</p>
  
  <pre><code>&lt;div class="attribute-2"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JavaScript function 1:</p>
  
  <p>Needs to get all html nodes with the attribute:</p>
  
  <pre><code>attribute-1
  </code></pre>
  
  <p>JavaScript function 2:</p>
  
  <p>Needs to get all html nodes with the attribute:</p>
  
  <pre><code>attribute-2
  </code></pre>
  
  <p>I have found this resource that states that this should not be done: <a href="http://roytomeij.com/blog/2012/dont-use-class-names-to-find-HTML-elements-with-JS.html" rel="nofollow">http://roytomeij.com/blog/2012/dont-use-class-names-to-find-HTML-elements-with-JS.html</a></p>
  
  <p>I have also found the following information:</p>
  
  <p>There are 5 main ways of querying DOM:</p>
  
  <ol>
  <li>getElementById</li>
  <li>getElementsByTagName</li>
  <li>getElementsByName</li>
  <li>getElementsByClassName (except IE&lt;9)</li>
  <li>querySelector (except IE&lt;8 and IE8 in compat mode)</li>
  </ol>
  
  <p>So basically, I am asking, how should html nodes be found using javaScript, where I am decorating the html nodes myself? Should I use classes, data attributes or something else?</p>