0

I am performing some DOM manipulation once my page loads and I was hoping to add some html right before an a specific div on the page. Not sure what I'm doing wrong here, I'm sure there's a simple way to accomplish this...

var finalStringHtml = '<div id="chartLinks">' + tableString + '</div>';

$(finalStringHtml.html().insertBefore("#chart_div")); //fails
$(toString(finalStringHtml).html().insertBefore("#chart_div")); //fails
1

1 Answer 1

2

You don't need the .html() call. (full docs: http://api.jquery.com/insertbefore/)

Try:

$(finalStringHtml).insertBefore("#chart_div");

If you want to, you can do the full code on one line and not create the variable:

$('<div id="chartLinks">' + tableString + '</div>').insertBefore("#chart_div");
Sign up to request clarification or add additional context in comments.

Comments

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.