appenddivで色を編集できないのはなぜですか。
ボタンをクリックして、新しいdiv呼び出し'block2'を追加します。$(this)を使用すると、機能しません。それを修正する方法は?
HTML
<div id="btn"><input name="click" type="button" value="Click" /></div>
<div class="block1" style=" width:100px; height:100px; background:orange;">I am Block1</div>
JS
$('#btn').click(function(){
var $newDiv=$('<div class="block2" style=" width:100px; height:100px; background:green;">I am Block2</div>');
$( "#btn").parent().append($newDiv);
});
$('.block1').click(function(){
$(this).css('background', 'blue');
});
$('.block2').click(function(){
$(this).css('background', 'blue');
});