Remove 'this' div.
Hi all
http://www.ttmt.org.uk/
I have this simple example here were you can click the 'Add Block' btn
to add div's that contain a 'DELETE' span.
I want to delete 'this' div when the span is clicked.
I have looked online but I can't see how to do it.
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <style type="text/css" media="screen"> *{ margin:0; padding:0; } button{ cursor:pointer; margin:20px 0 0 20px; padding:10px; } #wrap{ margin:20px; } #wrap .container{ background:red; width:300px; height:150px; margin:0 0 10px 0; position:relative } #wrap .container span{ background:white; cursor:pointer; font-weight:bold; padding:10px; position:absolute; top:20px; right:20px; } </style> </head> <body> <button id="btn">Add Block</button> <div id="wrap"> </div> <script type="text/javascript" charset="utf-8"> $('#btn').click(function(){ $("<div class='container'><span>DELETE</span></div>").appendTo('#wrap'); $('.container span').click(function(){ $('.container', this).remove(); }) }) </script> </body> </html>



Reply With Quote


Bookmarks