0

Is there a way to reload only a part of a webpage, e.g. a divelement without using AJAX or JQuery? I tried document.getElementById("mydiv").reload(); but it obviously doesn't work.

Please, do not write JQuery or AJAX, only pure JavaScript!

Alex
  • 3,719
  • 7
  • 35
  • 57
  • No, there is no way to reload only some elements without ajax. – adeneo Dec 08 '15 at 01:20
  • reload it from the server? – Shanimal Dec 08 '15 at 01:21
  • But since it's possible to do it with JQuery, then there should be a way to get the same result with JavaScript, because the the former is a subset of JavaScript? – Alex Dec 08 '15 at 01:22
  • No, there isn't a built-in way to reset an element to its original state. You can perhaps stash a copy of its initial contents, attributes, etc. as the page loads, then replace what becomes current when needed. ([` – Jonathan Lonowski Dec 08 '15 at 01:23
  • Forgot to put a note: so far it's a client-side website. But even from within webserver, I'll need to resort to AJAX anyway? – Alex Dec 08 '15 at 01:23
  • Ajax really has nothing to do with jQuery, it's really called `XMLHttpRequest` and is available without jQuery as well. Sounds like you really mean you don't want to use jQuery, not ajax. – adeneo Dec 08 '15 at 01:25
  • http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java This might help you. – crassfh Dec 08 '15 at 01:30

1 Answers1

0

If you are client-side only and you want to use JavaScript to update a div then replacing the inner html of the div might just do the trick.

Something like :

document.getElementById("content").innerHTML = "whatever";

Or if you prefer to use jquery :

$('#content').html('whatever')
ForguesR
  • 3,558
  • 1
  • 17
  • 39
  • What if the content (i.e. `innerHTML`) remains the same? What changes is the `div` element's `top` value, whose original value is described in an external CSS style. Is there a method to retrieve that initial value or should I record it manually, before making any changes to `div`? – Alex Dec 08 '15 at 01:46
  • Well this is completely different. You can use two style rules in the CSS file. Updating the `div` without jQuery would be cumbersome. With jQuery it would be : `$( "#content" ).removeClass( "oldClass" ).addClass( "newClass" );` – ForguesR Dec 08 '15 at 02:04