JavaScript innerHTML breaking setInterval

Does anyone know why this happens? Placing an image and then setting a setInterval function to animate it. Then adding HTML to the parent div breaks the animation.

document.getElementById('whiteboard').innerHTML = '<img id="mule" src="http://childscript.com/art/mule.png" />';  //image with id mule

csE = document.getElementById('mule');
setInterval(function(){ csE.style.transform = 'rotate(' + Math.floor(Math.random() * 90 -45) + 'deg)'; }, 100);

// following line breaks the code???
document.getElementById('whiteboard').innerHTML += 'hey';

JSfiddle: http://jsfiddle.net/gt6w3dhb/

Answer:1

I'm trying to code an exercise in html page with javascript, to calculate the mean of a random array of 6 numbers that generated from randomArray() function. After the first loading of the page and ...

I'm trying to code an exercise in html page with javascript, to calculate the mean of a random array of 6 numbers that generated from randomArray() function. After the first loading of the page and ...

  1. pass values from child to parent react
  2. pass values from view to controller mvc
  3. pass values from powerapps to flow
  4. pass values from html to javascript
  5. pass values from view to controller
  6. pass values from parent to child angular
  7. pass values from javascript to php
  8. pass values from lightning component to flow
  9. pass values from html to php
  10. pass values from activity to fragment
  11. pass values from aura to lwc
  12. pass values from html to html
  13. pass values from servlet to jsp
  14. pass values from jsp to java class
  15. pass values from js to html
  16. pass values from fragment to fragment android

I need a horizontal scroll bar for twitter timeline,as of now the options provided by twitter API is vertical scroll bar or no scroll bar,how can i achieve this? Code used: <DIV class="twit"> ...

I need a horizontal scroll bar for twitter timeline,as of now the options provided by twitter API is vertical scroll bar or no scroll bar,how can i achieve this? Code used: <DIV class="twit"> ...

I'm having trouble to create image slideshow. An image fetched from data base and binded into view model. it working fine. now i want to create slideshow with available images. i had tried like this. ...

I'm having trouble to create image slideshow. An image fetched from data base and binded into view model. it working fine. now i want to create slideshow with available images. i had tried like this. ...

I need a way to get the element pressed in a function called by that element, and disable it. I tried using $(this), but is not working, this is my code: <script> function x(){ $(this)....

I need a way to get the element pressed in a function called by that element, and disable it. I tried using $(this), but is not working, this is my code: <script> function x(){ $(this)....

  1. jquery javascript onclick
  2. jquery onclick javascript function
  3. javascript jquery onclick button
  4. javascript jquery onclick element