Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Swap DOM objects in / out to object variables?

Reply
Thread Tools

Swap DOM objects in / out to object variables?

 
 
Martin Honnen
Guest
Posts: n/a
 
      01-28-2005


John Doe wrote:

> Actually W3C specifies that getElementById returns the first element
> with the supplied id, so the functionality of that part should be
> standard


No idea where you think the W3C states that but the current DOM Level 2
Core in
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document>
clearly says about getElementById on the document node:
"Behavior is not defined if more than one element has this ID."

> What about the insertAdjacent? Also not in the official DOM
> methinks.


insertAdjacentHTML in IE's DOM cannot be done with DOM Level 1 and 2 API
as it requires parsing of markup obviously, with Mozilla however it
can be emulated as Mozilla has an extension to parse HTML.
insertAdjacentElement can be done but while in IE's DOM you call that
method on one node and then the argument e.g. 'afterEnd' decides on the
actual parent the node is inserted in in the W3C DOM you will need to
have your code find the right place to insert so
element.insertAdjacentElement('beforeEnd', newElement)
would translate to
element.appendChild(newElement)
and
element.insertAdjacentElement('afterBegin', newElement)
to
element.insertBefore(newElement, element.firstChild)
while for
element.insertAdjacentElement('beforeBegin', newElement);
you need
var parentNode = element.parentNode;
if (parentNode) {
parentNode.insertBefore(newElement, element);
}
and for
element.insertAdjacentElement('afterEnd', newElement)
should be
var parentNode = element.parentNode;
if (parentNode) {
parentNode.insertBefore(newElement, element.nextSibling);
}

All written down from memory and not tested at all so don't rely blindly
on that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      01-28-2005
JRS: In article <sSjKd.319$(E-Mail Removed)>, dated Fri, 28
Jan 2005 05:14:00, seen in news:comp.lang.javascript, Zifud
<(E-Mail Removed)> posted :
>
> The W3C DOM 1 and 3 specs say the same thing:
>
> "getElementById
> "Returns the Element that has an ID attribute with the given
> value. If no such element exists, this returns null. If more
> than one element has an ID attribute with that value, *what is
> returned is undefined.*" (my emphasis)
>
><URL:http://www.w3.org/TR/2004/REC-DOM-Le.../core.html#ID-
>getElBId>
>
> The W3C specification actually says to return undefined.



I don't know what W3C intended to mean.

But the quoted words mean that what is returned is nor defined,
uncertain, unreliable, etc.; not that the special state _undefined_ is
required to be returned.

However, if the quoted "undefined" was textually distinguished, it might
stand for the special value.

Tip to W3C and others : when defining a language in which a special
value called "undefined" exists, never use the word "undefined" where
"not defined" would do.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
John Doe
Guest
Posts: n/a
 
      01-28-2005
>
> No idea where you think the W3C states that but the current DOM Level 2
> Core in
> <http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document>
> clearly says about getElementById on the document node:
> "Behavior is not defined if more than one element has this ID."

You are right of course. I feel both sheepish and chastened. Don't
know where I got that. It wasn't from M$ and it (obviously) wasn't from
the W3C. I'll be more careful about who I'm relying on in the future.
Thanks for the tip on the alternative to adjacentelement code.
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      01-28-2005
Dr John Stockton wrote:
<snip>
> Tip to W3C and others : when defining a language in which
> a special value called "undefined" exists, never use the
> word "undefined" where "not defined" would do.


The W3C DOM specifications are intended to be programming language
neutral, expressing their interface definitions in IDL (rather than any
of the languages for which they explicitly provide binding documents).
As a result the term 'undefined' should have no meaning other than its
common English usage in that context. Within the DOM binding documents
specifically aimed at ECMAScript the term might be more ambiguous.

Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Swap" baseclass of two similar Objects... .rhavin grobert C++ 5 10-07-2007 09:30 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
What swap is called when using std::swap? Niels Dekker (no reply address) C++ 4 07-20-2006 08:44 PM
Convert a XML DOM Object to a HTML DOM Object manjunath.d@gmail.com XML 0 09-20-2005 08:16 AM
How to swap two rows using JS + DOM ? Timmy Javascript 1 06-17-2005 04:36 PM



Advertisments