2

I have footer code below. I want to add some html content (see below) but if I do it, the default content disappear. I want to keep default content and add the new one. How to do that?

<div id="footer">
HTML content and some classes
</div>

And my code to add another HTML content with classes:

<script>
document.getElementById('footer').innerHTML = '<div class="bannery"><img class="obrazek" src="URL"></div>';
</script>

Thank you :-)

2
  • 2
    Look at appendChild Commented Jul 19, 2018 at 21:28
  • Added this answer to the dupetarget, as it didn't have the obvious answer. Commented Jul 19, 2018 at 21:47

1 Answer 1

3

Try this : document.getElementById('footer').innerHTML += '<div class="bannery"><img class="obrazek" src="URL"></div>'; That should work

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

4 Comments

Issue with this is if there is event handlers, you remove them.
It is supposed to add inject HTML to the element with the footer id
Usually works for me
It will add it, just saying there are side effects to this solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.