With jQuery I can update the contents of a div I using $.load(). How can I update a div in pure JavaScript?
3 Answers
As suggested by Julian H. Lam:
var req = new XMLHttpRequest();
req.open("POST", "address_for_div_content", true);
req.onreadystatechange = function () {
if (req.readyState != 4 || req.status != 200) return;
document.getElementById('id_of_div')=req.responseText;
};
Here the documentation for XMLHttpRequest
Comments
Pure JavaScript (not JQuery) solution : wrap your div in an iframe, give it an id myFrame, then refresh it from the child like this:
parent.document.getElementById("myFrame").reload();
1 Comment
Felix Kling
I guess "wrap your div in an iframe" actually means "create a new page with just the
div's content and load it via an iframe"
.innerHTMLto update element contents.