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

I am adding an element on a certain condition. But I don't want it suddenly appear but rather woul

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();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745231991a4617718.html

相关推荐

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

    I am adding an element on a certain condition. But I don't want it suddenly appear but rather woul

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信