Megha Paul Megha Paul - 5 months ago 12x
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.


You need to use .addClass():

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

Working Fiddle