Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove innerHTML from div

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();

like image 734
PositiveGuy Avatar asked Apr 15 '10 20:04

PositiveGuy


People also ask

How do I remove an innerHTML element?

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.

How use innerHTML with div tag?

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.

How do you replace innerHTML?

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.

Why innerHTML should not be used?

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.


1 Answers

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(); 
like image 86
womp Avatar answered Sep 29 '22 10:09

womp