最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Combine after() and slideDown() - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

4 Answers 4

Reset to default 4

Try 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();
});
发布评论

评论列表(0)

  1. 暂无评论