Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery fadeIn not working

Tags:

jquery

Can someone please tell me what I'm doing wrong:

style:

.warning{border: 1px solid #F0AAAA; background:#FFBABA; color: #C90000;} 

markup:

 <p class="warning">A successful authorization already exists.                      Further authorizations are not allowed at this time.</p> 

script:

 $().ready(function () {      alert($(".warning").html());     // WORKS      $(".warning").fadeIn(4000);      // DOESN'T WORK  }); 
like image 869
DS. Avatar asked Aug 03 '10 17:08

DS.


People also ask

What is fadeIn in jQuery?

The fadeIn() Method in jQuery is used to change the opacity of selected elements from hidden to visible. The hidden elements will not be display. Syntax: $(selector).fadeIn( speed, easing, callback )

What is fadeIn and fadeOut in jQuery?

The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent. Note – jQuery does the fading by changing the opacity of the element.

Which of the following method accepts opacity as parameter in jQuery?

The . fadeIn() method animates the opacity of the matched elements.


1 Answers

Unless the element is hidden, no fade will occur, you need something like this:

$(".warning").hide().fadeIn(4000); 

You can give it a try here, also $() is deprecated in 1.4+, you should use $(document) or the shorter version, like this:

$(function() {   $(".warning").hide().fadeIn(4000); }); 

The alternative is to give the element a display: none initially but this breaks for JS-disabled users, or if JavaScript errors occur preventing the fade, so you may want to steer clear of this approach.

like image 140
Nick Craver Avatar answered Sep 18 '22 22:09

Nick Craver