Indicate window.closein your html handler:
<a onclick="window.close();">close<a>
http://jsfiddle.net/ZTwd7/1/
Otherwise, it close()refers to its own method close, which does nothing.
This is how you emulate it using the javascript handler (as opposed to the built-in html attribute):
elem.onclick = function(event) {
with(Window.prototype) {
with(document) {
with(this) {
close();
}
}
}
};
This is not an exact reproduction (and it does not work in IE, etc.), but it puts .closein Window.prototypefront of the global window.closein scope, so it is shadow, you can still reference it using window.close().
jQuery:
<a id="view">something<a>
<a id="close">close<a>
JS:
$(function() {
$("#view").click(function() {
$('body').append('<div class="added"><p>something</p></div>');
});
$("#close").click(function() {
$('.added').remove();
});
});
http://jsfiddle.net/ZTwd7/5/
ajax, html, :
$.get("myhtml.html", function(html) {
$("body").append(html);
}, "html");