I'm currently using Ajax to pull data from my Json file... my situation is that in one div of my html i need to add a heading and paragraph..
I tried to make a property such as "headingpara": "<h1> blah blah </h1> <p> blah blah blah </p>"
With this i get an error.
i also tried to do
"heading": "<h1> blah blah </h1>",
"para": "<p> blah blah blah </p>"
and then in my javascript call both properties with ["heading", "para"] but it only shows the paragraph and not the heading..
how can i put both the h1 and p tags side one div using this?
You can use the property innerHTML to concat your HTML strings building the content of the target div.
var ajaxresponse = { "heading": "<h1> blah blah </h1>", "para": "<p> blah blah blah </p>" }; document.querySelector('#target_div').innerHTML = ajaxresponse.heading+ajaxresponse.para;
<div id="target_div"></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.