Web Analytics Made Easy -
StatCounter DOM and CSS - CodingForum

Announcement

Collapse
No announcement yet.

DOM and CSS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DOM and CSS

    I have a javascript document that uses the DOM function to insert code in the body of an HTML document. However, I'm unsure on how to tell it where to put the code in the document. It's keeps putting it at the end of my document and not where it's being called from. Could somebody give me an example of how to make sure the code is put between "<div id(or class)="test"></div>" tags?

  • #2
    What is the markup that you wish to insert?

    generic e.g.
    Code:
    var newEl = document.createTextNode('Holy Moly!')
    
    // or
    
    var newEl = document.createElement('img');
    newEl.setAttribute('src','/images/myimg.jpg');
    newEl.setAttribute('alt','something suitable');
    
    document.getElementById('test').appendChild(newEl);
    …creates…

    Code:
    <div id="test"><img src="/images/myimg.jpg" alt="something suitable"></div>
    Why you should validate your code before asking for help...

    Comment


    • #3
      Thanks, works like a charm now!

      Comment

      Working...
      X