How to add HTML file to json file

I have a json file from which HTML content is loaded and displayed in a browser

"content": "Hello World <h1 class=\"page-title\">H1 Heading HTML tag</h1> <p>Para Tag</p>",

This works when the HTML content is small.

How should I handle large HTML content blocks such as slider or harmonics. Is it possible to call a file instead of content.

thank

+4
source share
2 answers

Try to use html,.load()

HTML

// e.g., "/path/to/html/"
<div id="first">Hello World 1 <h1 class="page-title">H1 Heading HTML tag</h1> <p>Para Tag</p></div>
<div class="second">Hello World 2 <h1 class="page-title">H1 Heading HTML tag</h1> <p>Para Tag</p></div>
<img src="image-1">
<img src="image-2">

Js

$("#container1").load("/path/to/html/ #first");
$("#container2").load("/path/to/html/ .second");
$("#container3").load("/path/to/html/ [src=image-1]");
$("#container4").load("/path/to/html/ img:eq(1)");
+3
source

Yes, you can. load the contents of the div as shown below.

$.get('json.JSON',function(result){
   //You will get the JSON data in result
   $("#container").html(result.content);            
});
0
source

All Articles