0

i try to load a html File in a div and to remove the html with a click on a id inside the html Resource. Clicking on id="load" create a empty div (id="externContent") within div (id="showContent") and load the extern Resource extern.php #wrapp into id="externContent". Successfully Click on id="close" deletes extern Resource inside div id="externContent". Successfully

Why does not it click on id="closeExtern" deletes extern Resource inside div id="externContent".

Basic html

<div id="load">Load</div>
<div id="close">Close/div>id
<div id="showContent"></div>

Script in Basic html

$('#load').click(function() {
    $('#showContent').append('<div id="externContent"></div>');
    $('#externContent').empty();
    $('#externContent').load('extern.php #wrapp');
});
$('#close').click(function() {
    $('#externContent').empty();
});
$('#closeExtern').click(function() {
    $('#externContent').empty();
});

load extern.php

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>
<div id="wrapp">
some content
<span id="closeExtern">CloseExtern/span>
</div>
</body>
</html>
Barmar
  • 741,623
  • 53
  • 500
  • 612
apollo23
  • 1
  • 1
  • You don't need to use `.empty()` before `.load()`. Especially since you just created the empty DIV. – Barmar Feb 13 '15 at 23:37
  • You need to use `$("#showContent").on("click", "#closeExtern", function()...);` to bind to the dynamically-loaded DIV. – Barmar Feb 13 '15 at 23:39
  • $("#showContent").on("click", ".#closeExtern", function(){ $("#externContent").empty(); }); – apollo23 Feb 14 '15 at 18:34

0 Answers0