0

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?

1
  • 3
    "With this i get an error" -> which one? moreover, please share your code in a fiddle or something, we can't help you if we can't see what you're doing. Commented Oct 17, 2017 at 7:50

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

This didn't fix my problem although it gave me an idea to put .heading and .para into seperate variables and then concat them together. Thank you for this help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.