Results 1 to 3 of 3

Thread: HTML DOM - problem with a div

  1. #1
    Join Date
    Feb 2013

    HTML DOM - problem with a div

    So I've this little code:

    <!DOCTYPE html>
    		<div id="first">
    			var x=document.getElementById("first");
    As far as I understand, the <p> inside the <div> should be its child, and in this case the first and last child. In that case, the script should alert "Hello" since it's the innerHTML of the <p> element.
    Obviously I'm missing something and would love to be enlightened.

  2. #2
    Join Date
    Mar 2011
    According to w3schools.com, apparently browsers other than Internet Explorer treat white spaces (including line feeds) as text nodes. See http://www.w3schools.com/dom/prop_el...firstchild.asp. So you're probably best off using a function similar to the one they give as an example in order to crawl the child elements to make sure you find the one you really want.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Feb 2013
    Thanks, that solved my problem. Just one thing, I'm only learning HTML DOM and javascript, and using the doctype HTML, so how come XML rules apply?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center