Add new class and attributes to div if it exists on the page
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11618822/how-to-add-new-class-and-attributes-to-div-if-it-exists-on-the-page">How to add new class and attributes to div if it exists on the page</a>  </p>
</blockquote>



<p>I need JavaScript code on my master page which tries to find if a div exists. If so, it should add a new class and also add a new id attribute.
For example if the page has this div:</p>

<pre><code>&lt;div class="toplink"&gt;abc..&lt;/div&gt;
</code></pre>

<p>Then JavaScript code should make it exactly like this:</p>

<pre><code>&lt;div class="toplink adin" data-aid="114"&gt;abc..&lt;/div&gt;
</code></pre>

<p>The code inside the div should remain the same.</p>

<p>I tried this code but this is not working</p>

<pre><code>    &lt;script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"&gt;
    if ($('.toplink').exists()) {
        $('.toplink').addClass('adin').attr('data-aid', '114');
    }
&lt;/script&gt;
</code></pre>

<p>What wrong with this code? what where i placed this code,in header on footer?
Can i do this with javascript, not jquery</p>
