Reputation: 652
I have a table that displays data in it. I have created a button that allows the user to select a date, and then display the data for that date in the table. I am unsure how to clear out the original data before the new data displays. At this point it's just displaying what was originally selected plus the new data. Here's my code:
<script>
$(".spiffdate-btn").click(function(){
var correctId = $("ul.spiff_tabs li.active a").attr('data-id');
var startDate = $("#startDate").val();
if (startDate == "") {
} else {
if (correctId == "delayedspiff")
{
$.get("@Url.Action("DelayedSpiff", "Dashboard")", { startDate: startDate }, function (data) {
$('#details').html(data);
});
} else if (correctId = "instantspiff") {
$.get("@Url.Action("InstantSpiff", "Dashboard")", { startDate: startDate }, function (data) {
$('#details').html(data);
});
}
}
});
</script>
How do I clear before $('#details').html(data);?
UPDATE:
This is how the data loads when the view loads for the first time:
function pullDetails(carrierId, startDate, status, divid) {
$.get("@Url.Action("getDelayedSpiffOrderDetails", "Dashboard")",
{ carrierId: carrierId, startDate: startDate, status: status },
function (data) {
$('#' + divid + ' .submitted_details').html(data);
$('#' + divid + ' .submitted_details').html(data);
$('#' + divid).removeClass('carrier-hide');
});
}
How do I get it to clear this data when I run the new data?
Upvotes: 0
Views: 31
Reputation: 287
just simply set it to nothing
document.getElementById('details').innerHTML= '';
Upvotes: 1
Reputation: 5211
Try this code.
Before assigning data result to table, clear the contents using empty().
$(".spiffdate-btn").click(function(){
$('#details').empty();
$('#details').html(data);
});
Upvotes: 1