W3C home > Mailing lists > Public > public-comments-wcag20@w3.org > September 2005

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

From: olivier Thereaux <ot@w3.org>
Date: Fri, 2 Sep 2005 11:12:34 +0900
Message-Id: <634bf347e091f25fe023870a206605a3@w3.org>
To: public-comments-wcag20@w3.org

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 17 July 2011 06:13:19 GMT