views:

30

answers:

3

I am new to javascript and jquery. I have written some javascript code for some client validation.

document.getElementById(spnError).style.display = 'block';

This is how I am showing a span if there is some validation issues in the form. I want to use Jquery to show this span. I would like to slide it down slowly.

A: 

slideDown()

$('#spnError').slideDown('slow');
jAndy
+1  A: 

Replace milliseconds with how long you want it to take

$("#spnError").slideDown(milliseconds);

There are also three built in values

$("#spnError").slideDown("slow");
$("#spnError").slideDown(); //default speed
$("#spnError").slideDown("fast");
Malfist
Slight correction, there are [three built-in values](http://github.com/jquery/jquery/blob/master/src/effects.js#L455), `slow`: 600ms, `fast`: 200ms, and the default: 400ms.
Nick Craver
@Nick @Malfist Thanks. it worked. But I want to pass a string variable which will contain my spanid. $(#spnError).slideDown("slow");
vaibhav
+1  A: 

Since you're using a variable for the ID, you need the #ID selector and .slideDown(), like this:

$('#' + spnError).slideDown('slow');

without the # if spnError is say "mySpanElement", it's looking for that tag name, <mySpanElement>...to search by ID prepend a # to it :)

You can read more about jQuery selectors here and view a complete list here.

Nick Craver
Thanks. Although I figured it out myself. It was easy.
vaibhav