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="www.google.com">myclass</a></div>
This is what i am trying but not working
$('.myclass','a').attr('class','myclass');
Thanks in advance.
You need to use .addClass()
:
$('#mydiv a').addClass('myclass');
Working Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With