1

I have a "badly written" simple banner:

...
    <script>
    document.write('banner text')
    </script>
...

How to correct insert this banner to document using javascript ?

This code:

<div id="id"></div>
$('#id').html('\x3Cscript>document.write("banner text");\x3C/script>')

replace all text in document ...

2 Answers 2

1

insert HTML:

$('#id').html('banner text')

or for text only (avoid XSS by escaping mark-up):

$('#id').text('banner text')
Sign up to request clarification or add additional context in comments.

Comments

1

The problem isn't in the jquery code. It's just that calling document.write() after the page has loaded - it replaces all text in the document

Try this:

$('#id').html("Banner text")

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.