I just wat to know how I can reload a specific element or div with javascript code.
div:
<div id="profile_img">
<figure>
<img id="holla" src="avatar.gif"/>
</figure>
</div>
hope you will help . I really need it . Thank you
You can easily set the source of an image in JS:
document.getElementById("holla").src = "avatar.gif";
function refresh() {
document.getElementById("holla").src = "avatar.gif";
}
<div id="profile_img">
<figure>
<img id="holla" src="avatar.gif"/>
</figure>
</div>
<button onclick="refresh();">Refresh Image</button>
If you are trying to reload from server then you can do ajax call and set the response to that div. document.getElementById('holla').innerHTML = this.responseText;
You must have some mechanism to load the image. Ajax call will load the image asynchronously.
// Create an XMLHttpRequest object
const xhttp = new XMLHttpRequest();
// Define a callback function
xhttp.onload = function() {
//you get response back from server in responseText.
document.getElementById('holla').innerHTML = this.responseText;
}
// Send a request
xhttp.open("GET", "ajax_info.txt");// path to file
xhttp.send();