0

I am new to web development. I am developing a page and its broken down to various div elements. In order to decrease the data consumption, i want to update the contents of only a specific div element on trigger of any event and rest should be the same. How can I achieve that?

[edit] [code]

<html>
....
....
 <body>
    <div id="post">
        <h1>Post tile<h1>
        <img src="/s/smt.png">
         <p>this is the post desc</p>
    <div>
<div id="any other">
</div>
. 
. 
.
 <body>
</html>

Lets consider the above case where I am in need to dynamically update div "post" only without querying any other portion of the page.

important edit (@Milind Anantwar, thanks for making this comment): The update should be dependent to server. I mean, situation like I need to update that div from my database..

bibek shrestha
  • 448
  • 3
  • 9

1 Answers1

0

You can do something like this Demo:

var button = document.getElementById('b');
var div = document.getElementById('any_other');

var count = 0;
button.addEventListener('click', function() {
  // Updating div dynamically by click event on button
  div.innerHTML = 'This is dynamicaaly updated - ' + count + ' times';
  count++;
});
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168