开发者

How to use Jquery for sliding effect

开发者 https://www.devze.com 2022-12-30 23:07 出处:网络
I am new to javascript and jquery. I have written some javascript code for some client validation. document.getElementById(spnError).style.display = \'block\';

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

精彩评论

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

关注公众号