I need that when user will click on ‘div_id’ div will be null or empty – I do not want to hide it.
.empty() doesn’t work – the div just fast blinks and stays on the screen:
$(div_id).click(function () {
$(div_id).empty();
});
This is my all code:
function paintOrders(items) {
var container =
'<table border="2">' +
$.each(items, function () {
div_id = '#div_' + this.SHIPMENT;
container += '<tr>' + '<td>' + div_id + '--' + this.CUSTOMER_NAME + '</td>' + '</tr>';
});
container += '</table>';
$(div_id).click(function () {
$(div_id).empty();
});
$(div_id).append(container);
$(div_id).html(container);
}
When I use .empty or .html
the div blinks. What might be the problem?
.empty()is supposed to remove the child nodes, try.html('');instead.If you’re adding divs dynamically, you have to use .live instead of .click: