Sachin Kainth
Sachin Kainth

Reputation: 46760

Adding class to link in JQuery

I have a anchor tag and would like to add a class to it in my document ready function. How do I do that?

Thanks,

Sachin

Upvotes: 0

Views: 61

Answers (3)

The System Restart
The System Restart

Reputation: 2881

$(function() {  
   $('a:first').addClass('yourclass'); // suppose add class to first <a>
});

or

$('a:eq(1)').addClass('yourclass'); // suppose add class to second <a> and so on

or

$('a#some').addClass('yourclass'); // suppose add class to <a> have id 'some'

Upvotes: 1

Imdad
Imdad

Reputation: 6042

$(document).ready(function() {  
   $('#id1_of_a, #id2_of_a, #id3_of_a').addClass('myClass');
});

Upvotes: 1

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123428

$(function() {  
   /* domReady */
   $('a').addClass('yourclass');
});

of course if your link has an id use a more specific selector like

 $('#yourlink').addClass('yourclass');

Upvotes: 3

Related Questions