Click here to Skip to main content
15,850,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working with json data. I need write data to div content but after each request i have to clear content of "Secim" div. When i clean the "Secim" div content then "Secim" div never show again.

$.getJSON("Content/Chart/iron/alldata.json", function (data) {
    $("#Secim").html('');  //<-------- Here or
    $("#Secim").remove();  //<-------- Here or
    $("#Secim").empty();   //<-------- Here or
    $("#Secim").detach();  //<-------- Here and

    var items = [];
    $.each(data, function (key, val) {
        var Tarih = new Date(;
        if (Tarih < date1 && Tarih > date2) {
            items.push("<div id='" + key + "' class='list-group-item list-group-item-action'>" + + "                 " + val.value + "</div>");

    $("<div/>", {
        "class": "container list-group",
        html: items.join("")
    }).appendTo("#Secim");  //<-------- Here don't work together.

What I have tried:

I used these methods
Updated 12-Apr-21 0:47am

Of course the div never worked again. You removed it from the DOM!

How about you try setting the innerHTML property of the div element to an empty string?
$("#Secim").innerHTML = "";
Share this answer
gacar 12-Apr-21 3:59am    
Thank you for solution but now adding new table to old near now. Didn't remove old content.

I found solution with Richard Deeming's answer here,

$.getJSON("Content/Chart/insaat_demiri/karabukInceTum.json", function (data) {
            document.getElementById("Secim").innerHTML = "";
            var startDate = new Date(Tarih1);
            var endDate = new Date(Tarih2);

            var filteredData = $.grep(data, function (a) {
                var aDate = new Date(;
                return aDate >= startDate && aDate <= endDate;

            var div = $("<div/>", { "class": "container list-group" });

            $.each(filteredData, function (key, val) {
                var item = $("<div/>", {
                    id: key,
                    "class": "list-group-item list-group-item-action"


Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900