2017-01-12 2 views
2

クリックイベントで新しいhidden divを動的に追加しようとしましたが、このdivをフェードインしました。新しく追加された要素の.fadeIn()

$('.param').on('click',function(event){ 
     $(this).fadeOut('slow'); 
     $('#bibox').append('<div style="display: none;" id="test"> Hello World!</div>'); 
     $('#test').fadeIn('slow'); 
    }); 

新しい隠しdivを#biboxに正しく追加しますが、非表示にします。

+1

IDが一意 –

+0

である必要があり、実際、それはケースだ、ポストにテストケースのためにそれを変更しましたここに。 – Jbertrand

+0

あなたが提供したコードが動作するように見える再現可能な例を提供してください。 https://jsfiddle.net/xeqqsnsL/ –

答えて

2

はこれを試してみてください:

$('.param').on('click',function(event){ 
    $(this).fadeOut('slow'); 
    var html = '<div style="display: none;" id="test"> Hello World!</div>'; 
    $(html).hide().appendTo("#bibox").fadeIn('slow'); 
}); 
+0

作業するようです! oadeの前に隠す必要がありましたか? – Jbertrand

+0

いいえ、必要ありません! – mariobros

2

これは私のために働いている:

$('.param').on('click',function(event){ 
 
     $(this).fadeOut('slow'); 
 
     $('#bibox').append('<div style="display: none;" id="test"> Hello World!</div>'); 
 
     $('#test').fadeIn('slow'); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="param">Click me!</div> 
 
<div id="bibox"></div>

関連する問題