开发者

How to use Jquery for sliding effect

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开发者_JS百科 this span. I would like to slide it down slowly.


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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜