Download partial html using javascript inside

On my website, I load the html that is displayed on the server (nodejs) and paste it into the desired position (most often a div with the id content).

How do I paste the resulting html on the client so that script tags are included?

I use client-side underlining and rudders. But perhaps vanillas are also possible.

PS: Here is an example to show the difference between jQuery.html() and setting innerHTML -property:

http://jsfiddle.net/waxolunist/VDYgU/3/

+4
source share
3 answers

with jQuery

 $('div#content').html(loaded_html); 

without

 getElementById('content').innerHTML = loaded_html; 

Although you can do it your own way, a better idea would be to send json and render pages in the browser using the same templates that you (possibly) use on the server. I use doT, which I consider the best of all JavaScript-based templates (e.g. EJS, underscore).

+3
source

You can use jQuery for this. Just with

$. Load ("# divname"). Load (URL)

http://api.jquery.com/load/

0
source

You have trouble escaping your character, use jshint . Otherwise, it is quite simple to use, for example

 var script1 = "content for jQuery"; var script2 = "content for javascript"; $(document).ready(function (){ $('#content1').html(script1); document.getElementById('content2').innerHTML = script2; }) 
0
source

Source: https://habr.com/ru/post/1479410/


All Articles