possible errors in [Client-side Scripting Techniques: 2.2 Dynamic content generation]

Hello WCAG editors!

I am not a DOM expert, by far, so this comment is to be taken with a 
lot of caution, but I think the "good practice" example in [Client-side 
Scripting Techniques: 2.2 Dynamic content generation] (from the W3C 
Working Draft 30 June 2005) is wrong in a couple of aspects:

* [[ para.insertText("Lorem ipsum dolor sit amet"); ]]
this seems wrong, or at least I can't find its reference anywhere in 
the DOM specs.
I suggest:
[[
var text = document.createTextNode("Lorem ipsum dolor sit amet");
para.appendChild(text);
]]

* idem for the list, which is also wrong because of mistakes in 
appendChild'ing
Instead of
[[
		var list = document.createElement("ul");
         itemone = document.createElement("li");
         itemonelink = document.createElement("a");
         itemonelink.setAttribute("href","foo.html");
         itemonelink.insertText("foo");
         list.appendChild(itemone);
]]
the correct script would be, I think (with extra title for the link -- 
you may change the text ;) but this is an example of setting several 
attributes, and title for a href's isn't a bad case where that would be 
needed):
[[
		var list = document.createElement("ul");
         var itemone = document.createElement("li");
         var itemonelink = document.createElement("a");
         itemonelink.setAttribute("href","foo.html");
		itemonelink.setAttribute("title", "CLICK HERE!!!");
         var linktext =document.createTextNode("foo");
		itemonelink.appendChild(linktext);
		itemone.appendChild(itemonelink);
         list.appendChild(itemone);
]]

I hope my suggestions aren't terribly wrong, and I hope they help.
Regards,
-- 
olivier

Received on Friday, 2 September 2005 02:12:43 UTC