• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 674
  • Last Modified:

Delete appended div with jquery

Hello,

I am trying to delete a div after it was dynamically loaded by jquery but it does not remove it.

Please see my code, any guesses on how to delete it?
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<div class="ap">some text</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(".ap").click(function(){
		$(".ap").after("<div><div class='delete'>x</div>aaaa</div>");
	});
	$(".delete").click(
	function(){
		$(this).parent().remove();
		}
	);
</script>

</body>

</html>

Open in new window

0
degaray
Asked:
degaray
1 Solution
 
leakim971PluritechnicianCommented:
use : http://api.jquery.com/live/
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<div class="ap">some text</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(".ap").click(function(){
		$(".ap").after("<div><div class='delete'>x</div>aaaa</div>");
	});
	$(".delete").live("click",
	function(){
		$(this).parent().remove();
		}
	);
</script>

</body>

</html>

Open in new window


or :

<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<div class="ap">some text</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(".ap").click(function(){
		$(".ap").after("<div><div class='delete'>x</div>aaaa</div>");
	$(".delete").click(
	function(){
		$(this).parent().remove();
		}
	);

	});
</script>

</body>

</html>

Open in new window

0
 
degarayAuthor Commented:
Thanks a lot!!!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now