I am having trouble exporting div data using Jquery. The values are all appearing in the same cell.
Check out the initial example image:
https://i.sstatic.net/6weMh.png
Now, take a look at the desired example image:
https://i.sstatic.net/LCjp4.png
I must have missed something in my code. Any assistance is appreciated.
JS:
var csvContent = "First Name, Middle Name, Last Name"; // CSV file headers
var dataElements = document.getElementsByClassName("sample");
for (var i = 0; i < dataElements.length; i++) {
// Iterating through each data entry
var entryLineCsv = document.getElementById("kaf70").innerHTML + ","
+ document.getElementById("kaf71").innerHTML + ","
+document.getElementById("kaf72").innerHTML + ",";
createCsvFile(entryLineCsv);
}
function createCsvFile(addEntryLineIoCsv) {
let file = new Blob([csvContent = csvContent + addEntryLineIoCsv], { type: "application/vnd.ms-excel" });
let url = URL.createObjectURL(file);
let a = $("<a />", {
href: url,
download: "filename.xls"
}).appendTo("body").get(0).click();
}
HTML:
div class="losSection" id="secReviewerDemographics"><div class="losSectionHeader"><div class="losSectionSel losSectionTitle misign" data-originaltitle="Demographics">Demographics</div></div><div id="cpC_kf_secview_50" class="losSectionView"><div>
<div id="ExportDetails" class="sample">
<div class="tabularView">
<input type="hidden" name="kaf_78" id="kaf_78" aria-label="kaf_78" value="01" class="._shCE">
<div id="cpC_ctl73" class="tabularTbl flex-row start-xs">
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_70" id="klb_70" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">First Name
</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_70" id="kaf_70">
<span class="labelValue" name="kaf_70" id="kaf70" aria-label="Applicant First Name">NAMA</span>
</span>
</div>
</div>
</div>
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_71" id="klb_71" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">Middle Name</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_71" id="kaf_71">
<span class="labelValue" name="kaf_71" id="kaf71" aria-label="Applicant Middle Name">VEENESH</span>
</span>
</div>
</div>
</div>
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_72" id="klb_72" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">Last Name
</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_72" id="kaf_72">
<span class="labelValue" name="kaf_72" id="kaf72" aria-label="Applicant Last Name">KUMAR</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div>
<button id="ExportToExcel" onclick="exportF(this)">Export To Excel</button>
DEMO Code: DEMO LiNK