2

I have a #myDiv And i want, when page load, ad class to #myDiv

E.G. Page load, #myDiv.class

I use this code but it's not working:

$('#sky').addClass(‘animate-in’); 
1

5 Answers 5

2

$(document).ready(function(){ is called whn the doucument is ready. and your addClass .. use single or double quotes to enclose the class ( not ‘ )..

try this...

 $(document).ready(function(){ 
   $('#sky').addClass('animate-in'); 
});

UPDATED

another div

<div id="anotherdiv"></div>

call the click function and the jquery selector to which u want to change the class

$('#anotherdiv').click(function(){
    $('#sky').addClass('animate-in');  //or any other new class
});    

go thorugh the selector jquery documentation..

http://api.jquery.com/category/selectors/

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it's working! Well, how can i add class to sky, when click another div?
1

You need to use single or double quote to enclose your class.

Change

$('#sky').addClass(‘animate-in’); 

To

$('#sky').addClass('animate-in'); 

or

$('#sky').addClass("animate-in"); 

Comments

0

you can do it like this

$(function () {
   $('#sky').addClass('animate-in'); 
});

OR

$(function () {
    $('#sky').addClass("animate-in"); 
});

Comments

0

use this code

   <body onload='$("sky").addClass("animate-in")' >

Comments

0

Please check that already any classes are available in $("#sky") and if u want to use only 'animate-in',

Can try this,

$("#sky").attr('class','');

$("#sky").addClass('animate-in');

so that we can come to know that, already existing things are cleared and adding a new one

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.