views:

21

answers:

2

I am trying to hide a div with a fadeout effect but it doesn't seem to work..

$('#messageDiv').hide().fadeOut('slow'); Any suggestion.

I am showing an error div using a custom function?

function getErrorMsgStyle(txt) {
    return "<table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'><tr style='line-height:7px;'><td>&nbsp;</td></tr></table><div class='error_Style_Border' id='messageDiv'><a href='javascript:void(0);' onClick=\"$('#messageDiv').fadeOut('slow');\"  class='link'><table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'><tr style='line-height:2px;'><td>&nbsp;</td></tr><tr><td class='table_error_Style_Border'><table width='97%' border='0' cellpadding='0' cellspacing='0' align='center' >" + "<tr style='line-height:2px;'><td colspan='15' align='center'></td></tr>" + "<tr ><td width='10px'>&nbsp;</td><td colspan='12' align='center' ><span class='error-txt'>" + txt + "</span></td><td width='10px' class='error-close'>X</td><td>&nbsp;</td></tr></table></td></tr>" + "<tr style='line-height:2px;'><td>&nbsp;</td></tr></table></a></div><a href='javascript:void(0);' onClick=\"$('#messageDiv').fadeOut('slow');\" class='link'><table width='100%' border='0' cellpadding='0' cellspacing='0' align='center'><tr style='line-height:7px'><td>&nbsp;</td></tr></table></a>";
} 

Also $('#messageDiv').fadeOut('slow'); doesn't seem to work

+2  A: 
$('#messageDiv').fadeOut('slow');

or

$('#messageDiv').fadeOut(250);

meaning the fade should take 250 milliseconds.

Ensure also that your element has the name of messageDiv and not something else.

edit

You could use a classname instead if the id if you are using webForms and finding that the id is not what you're expecting. I actually prefer this approach as it's less hit-n-miss

edit 2

Change your href to href='.' and your click event to $('#messageDiv').fadeOut('slow');return false;

griegs
@griegs ya i am using webforms.. But still i cant make it to work
Pandiya Chendur
Change your href to href='.' and your click event to $('#messageDiv').fadeOut('slow');return false;
griegs
The above works on my system
griegs
@greigs i got it to work...
Pandiya Chendur
@greigs what's the point in making a change to href could u explain
Pandiya Chendur
I've never actually seen the javascript notation you used with void(0) so I removed it. :)
griegs
@greigs i ve accepted the answer...
Pandiya Chendur
Thank you, glad I could help you. Have fun @Pandiya
griegs
@greigs it shows a jumping effect how to avoid it?
Pandiya Chendur
Jumping effect? it might just be the broswer, IE i've noticed can do a lot of jumping. You might also have a lot of elements on the page that the browser is trying to move up as you hide your error.
griegs
btw: i tried it here and there was no jumping in IE but it was on a page with few elements on it.
griegs
+1  A: 

You're using this in your error div:

<a href='javascript:void(0);' onClick=\"$('#messageDiv').fadeOut('slow');\"  class='link'>

Since you're using jQuery anyway, you might want to rewrite that particular tag by giving it an ID and attaching the onclick event using jQuery live().

Use:

<a href='#' id='hide_link' class='link'>

and use the following Javascript code somewhere below:

$(document).ready(function(){
     $('#hide_link').live('click',function(e){
         e.preventDefault();    // this will prevent the default link-click action
         $('#messageDiv').fadeOut('slow');
     });
});
Richard Neil Ilagan