jquery - JavaScript Appending Rather Than Overwriting Using InnerHTML Property -
so weird 1 every topic i've found on subject has exact opposite of problem.
i'm using javascript in sharepoint online replace innerhtml of elements, whenever function runs appending content rather overwriting it.
i've tried js method of setting innerhtml else first, value (no luck), , moving jquery call set it. in both cases same thing. same problem observed on both edge , chrome.
code below - ideas? (have not included whole script, specific function it's quite big script , other bits working expected).
function getthiscompany() { thiscompanyenum = thiscompany.getenumerator(); while (thiscompanyenum.movenext()) { var currentcompany = thiscompanyenum.get_current(); var thiscompanyid = currentcompany.get_item('id'); var thiscompanyname = currentcompany.get_item('companyname'); var thiscompanyphone = currentcompany.get_item('companyphone'); var thiscompanyurl = currentcompany.get_item('companyurl'); var thiscompanylogo = currentcompany.get_item('companylogo'); // check null value - if null console throws error , stops script, load default logo if (thiscompanylogo == null) { thiscompanylogo = "https://consiliumuk.sharepoint.com/poc/minicrm/crm%20images/nologo.png"; } else { thiscompanylogo = thiscompanylogo.get_url(); } var thiscompanyaddress = currentcompany.get_item('companyaddress'); var thiscompanymarkupblock = "<table><tr><td colspan=2><b>"; thiscompanymarkupblock += thiscompanyname; thiscompanymarkupblock += "</b></td></tr><tr><td colspan=1 valign=top><img height=100 width=100 src='"; thiscompanymarkupblock += thiscompanylogo; thiscompanymarkupblock += "' /></td><td colspan=1 valign=top>"; thiscompanymarkupblock += thiscompanyaddress; thiscompanymarkupblock += "<p /><i>"; thiscompanymarkupblock += thiscompanyphone; thiscompanymarkupblock += "</i><br /><a href="; thiscompanymarkupblock += thiscompanyurl; thiscompanymarkupblock += ">visit company website</a></td></tr></table><p /><input id='loadextended' type='button' value='load' onclick='loadextendeddetails("; thiscompanymarkupblock += thiscompanyid; thiscompanymarkupblock += ");' />"; alert(thiscompanymarkupblock); //document.getelementbyid('detailsspace').innerhtml = "loading..."; //document.getelementbyid('detailsspace').innerhtml = thiscompanymarkupblock; jquery("#detailsspace").html(thiscompanymarkupblock); } }
instead of using .html(), can use clear , append, yo ensure container empty, like:
jquery("#detailsspace").empty(); // before while while ([...]){ [...] jquery("#detailspace").append(thiscompanymarkupblock); // instead of html() }
Comments
Post a Comment