Reputation: 2781
I have a json file from which HTML content is fetched and displayed on the browser
"content": "Hello World <h1 class=\"page-title\">H1 Heading HTML tag</h1> <p>Para Tag</p>",
This works when HTML content is small.
How should I handle large HTML blocks of content such as a slider or accordian. Is it possible to call a file instead of the content.
Thanks
Upvotes: 4
Views: 1753
Reputation: 1
Try utilizing 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)");
Upvotes: 3
Reputation: 595
Yes you can. load div content like a below code.
$.get('json.JSON',function(result){
//You will get the JSON data in result
$("#container").html(result.content);
});
Upvotes: 0