This topic has been closed. No new entries allowed.
Reason: You can now post comments on articles on Dev Opera
You need to be logged in to post in the forums. If you do not have an account, please sign up first.
47: Creating and modifying HTML
When you have learned how to select specific HTML elements in the DOM using JavaScript, the next stage is to start modifying existing elements and adding new ones in response to user actions. In this article, Stuart Langridge show you how to do this by way of some classic examples, such as tabbed interfaces.( Read the article )
Like an earlier article, there is a style issue with declaring variables. Javascript variables have function scope, and so having vars deep inside a function is misleading, especially for programmers who are used to languages where variables have block scope. Javascript functions should declare all their variables once at the beginning of the function.
Hi to all. I am confused by part of the article:
"Adding the element to the document can be done in one of two ways: using appendChild as above,
or using insertBefore. The appendChild function adds our new element at the end of an existing
element (that’s why it’s called append). Since we want to add it in the middle of an existing
element, we need insertBefore."
I have understood, I need appendChild function to get text into newly created span element and of course I need to insert this whole element to document, then needed to use insertBefore. My confusion arrise from "Adding the element to the document can be done in one of two ways:..". My understandig is, I need both function to make it working. And then my confusion arrise more in "Excercise questions" by point "What’s the difference between appendChild and insertBefore?" I understood this two functions making diferent things, first append text to span element, second insert whole element to document.
Should someone make me clear where coming my confusion from? Thank you in advance, Jozef
"Adding the element to the document can be done in one of two ways: using appendChild as above,
or using insertBefore. The appendChild function adds our new element at the end of an existing
element (that’s why it’s called append). Since we want to add it in the middle of an existing
element, we need insertBefore."
I have understood, I need appendChild function to get text into newly created span element and of course I need to insert this whole element to document, then needed to use insertBefore. My confusion arrise from "Adding the element to the document can be done in one of two ways:..". My understandig is, I need both function to make it working. And then my confusion arrise more in "Excercise questions" by point "What’s the difference between appendChild and insertBefore?" I understood this two functions making diferent things, first append text to span element, second insert whole element to document.
Should someone make me clear where coming my confusion from? Thank you in advance, Jozef
both functions are for placing a child node into its new parent.
a child node may be
- an element node like an ordered list or a paragraph
- a text node
- an attribute
- a comment
see
http://www.devguru.com/technologies/xml_dom/16049.asp (append child)
http://www.devguru.com/technologies/xml_dom/16052.asp (insertBefore)
a child node may be
- an element node like an ordered list or a paragraph
- a text node
- an attribute
- a comment
see
http://www.devguru.com/technologies/xml_dom/16049.asp (append child)
http://www.devguru.com/technologies/xml_dom/16052.asp (insertBefore)