admin管理员组文章数量:1302410
How do I call a jquery function by just loading the page? For example, on one page,I have a paragraph and this jquery code here:
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
});
});
How do I make the paragraph slowly fade away using jquery right after the page loads WITHOUT having any user input like clicking the button?
How do I call a jquery function by just loading the page? For example, on one page,I have a paragraph and this jquery code here:
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
});
});
How do I make the paragraph slowly fade away using jquery right after the page loads WITHOUT having any user input like clicking the button?
Share Improve this question asked Jun 3, 2011 at 8:00 user701510user701510 5,77317 gold badges62 silver badges86 bronze badges4 Answers
Reset to default 3Just a small warning..
$('p')
will select all the paragraphs in the page..
use the selector more clearly..
to achieve the requirement, you can add this line as said above..
$("button").click();
or
$("button").trigger('click');
A much better way of wiring this is..
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
}).trigger('click');
});
this will improve the performance by reducing the no.of search cycles.. :)
cheers
Can't you just call hide like that:
$(document).ready(function(){
$("p").hide(1000);
});
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
});
$("button").click();
});
Just add that line.
just like this:
$(document).ready(function(){
$("p").hide(1000);
});
本文标签: javascripthow to call jquery function without having to trigger selector eventStack Overflow
版权声明:本文标题:javascript - how to call jquery function without having to trigger selector event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741668484a2391457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论