I'm trying to clear the div's innerHTML before repopulating it. I tried removeData() but once that's called, when I try to add the data, I get nothing from the next line after remove whereas if I remove the removeData() it's fine again. I just want to clear out any previous content in that div before I re-populate it.
divToUpdate.removeData(); //clean out any existing innerHTML div content first divToUpdate.html(data);
It looks like it never gets to my divToUpdate.html(data) for some reason after it calls that removeData();
innerHTML property innerHTML property will get or set the HTML markup contained within the element. But you can utilize this property to “remove” any elements within the container, by setting the value to an empty string. This property is fully cross-browser, read full docs on innerHTML.
innerHTML strings. You only need to + sign when inserting variables, not between HTML Tags. Also, you should use " only when opening & closing part of the string and ' for attributes. Or the opposite.
To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.
The use of innerHTML creates a potential security risk for your website. Malicious users can use cross-site scripting (XSS) to add malicious client-side scripts that steal private user information stored in session cookies.
jQuery Data is a different concept than HTML. removeData is not for removing element content, it's for removing data items you've previously stored.
Just do
divToUpdate.html("");
or
divToUpdate.empty();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With