Megha Paul Megha Paul - 2 years ago 108
Javascript Question

How to find anchor tag in div and add class?

I have a particular div class in which there is anchor tag with no class and i have to add class to it using jquery.
This is sample html

<div id="mydiv"><a href="">myclass</a></div>

This is what i am trying but not working


Thanks in advance.

Answer Source

You need to use .addClass():

$('#mydiv a').addClass('myclass');

Working Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download