PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] How to empty div

 October 27, 2022     javascript, jquery, jquery-events     No comments   

Issue

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?


Solution

.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:

$(div_id).live('click', function () {
        $(div_id).empty();
    });


Answered By - Shomz
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing