47: Creating and modifying HTML

Forums » Dev.Opera » Archived Article Discussions

This topic has been closed. No new entries allowed.

Reason: You can now post comments on articles on Dev Opera

Forum rules and guidelines

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

3. February 2009, 06:38:23

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 )

5. February 2009, 07:32:32

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.
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

1. April 2009, 12:40:36

jozefkrivan

Posts: 1

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

1. April 2009, 16:22:21

codebyjoe

Posts: 58

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)

25. June 2009, 14:51:32

Volvoxpl

Posts: 24

Im begginer in JS, but i dosnt really understand this part:

var el = document.getElementById('mypara');
mypara.style.display = 'none';


Why there is a
mypara.style.display
, and not
el.style.display
?
Well it seems, both versions work, but with your version there is no need of creating variable el

Forums » Dev.Opera » Archived Article Discussions