Click here to Skip to main content
15,867,453 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.

javascipt
$.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(val.date);
        if (Tarih < date1 && Tarih > date2) {
            items.push("<div id='" + key + "' class='list-group-item list-group-item-action'>" + val.date + "                 " + 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
$("#Secim").html('');
$("#Secim").remove();
$("#Secim").empty();
$("#Secim").detach();
Posted
Updated 11-Apr-21 23:47pm

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
 
Comments
gacar 12-Apr-21 3:59am    
Thank you for solution but now adding new table to old near now. Didn't remove old content.

image
I found solution with Richard Deeming's answer here,

JavaScript
$.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(a.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"
                });

                item.text(val.date);
                item.appendTo(div);
            });

            div.appendTo("#Secim"); 
        });
         
    }
 
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