admin管理员组文章数量:1415484
I am adding an element on a certain condition. But I don't want it suddenly appear but rather would like to slide it down. Here's how I add it:
$('.myDiv').after('<div>added content</div>');
How do I bine it with slideDown?
I am adding an element on a certain condition. But I don't want it suddenly appear but rather would like to slide it down. Here's how I add it:
$('.myDiv').after('<div>added content</div>');
How do I bine it with slideDown?
Share Improve this question edited Mar 10, 2017 at 12:32 Mohammad 21.5k16 gold badges57 silver badges85 bronze badges asked Oct 24, 2012 at 16:40 santasanta 12.5k51 gold badges161 silver badges266 bronze badges 3- Please expand your example code. Show us your HTML and the JS event you're using. – Kristen Grote Commented Oct 24, 2012 at 16:42
-
2
$('.myDiv').hide().after('<div>added content</div>').slideDown();
– Reinstate Monica Cellio Commented Oct 24, 2012 at 16:43 -
@Archer: Almost.
.after
returns the.myDiv
, not the new element. – gen_Eric Commented Oct 24, 2012 at 16:46
4 Answers
Reset to default 4Try this instead :
$(".myDiv").after("<div style='display:none;'>added content</div>");
$(".myDiv").next("div").slideDown();
Good Luck !!
Try this out:
$('.myDiv').after('<div style="display:none">added content</div>').next().slideDown();
You need to use .next()
on the div to which it is attached because .after()
... adds the element as a sibling to the div to which it is added
Try this
$('.myDiv').after('<div style="display:none;" class="newDiv">New Content</div>');
$('.myDiv').next('.newDiv').slideDown();
first make sure the new content that you input is hidden using .newdiv{display:none;}
either in your css file or inline code like: <div style="display:none;">
then use a callback function to only start after the code was inserted in the document when you used the after() method.
$('.myDiv').after('<div class="newdiv">added content</div>', function(){
$('.newdiv').slideDown();
});
本文标签: javascriptCombine after() and slideDown()Stack Overflow
版权声明:本文标题:javascript - Combine after() and slideDown() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745231990a2648864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论