第一个.click函数用于在容器中添加元素(div),第二个用于将其从容器中移除。该容器最初没有元素。通过点击删除功能是行不通的第二个.click()函数不起作用
$(document).ready(function(){
$(".class1").click(function(){
//Code for adding element to the container and
// removing class1 from it and adding class2
});
$(".class2").click(function(){
alert("hi"); //Even the alert is not displayed
$(this).fadeOut(100);
});
});
但是,它的工作原理,如果在页面加载到容器之前,元素已经存在。 任何原因为什么?是否因为document.ready函数?解决方案?
给我们您的HTML请。 –
请发布html – Sudantha
当您将事件添加到'.class2'元素时,您的元素是否已经存在? –