Comments on: Document CreateTag Method http://mattsnider.com/languages/javascript/document-createtag-method/ Understanding JavaScript and Frameworks Thu, 20 Nov 2008 21:00:37 +0000 http://wordpress.org/?v=2.1.2 By: MillsJROSS http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12081 MillsJROSS Wed, 16 Apr 2008 13:03:36 +0000 http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12081 JQuery natively does this by parsing through a string of how you'd write your HTML on the page. Not sure about Dojo, but it's probably a safe bet that most libraries have some method of doing this. This struck an idea in me, of a hackish way in which to create a very simple createTag, although, I haven't tested in extensively. The idea is that you have a hidden div tag with the id "createTag" and a function like this: function createTag(tagStr) { } JQuery natively does this by parsing through a string of how you’d write your HTML on the page. Not sure about Dojo, but it’s probably a safe bet that most libraries have some method of doing this.

This struck an idea in me, of a hackish way in which to create a very simple createTag, although, I haven’t tested in extensively. The idea is that you have a hidden div tag with the id “createTag” and a function like this:

function createTag(tagStr) {

}

]]>
By: MillsJROSS http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12082 MillsJROSS Wed, 16 Apr 2008 13:11:31 +0000 http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12082 Woops...accidently pressed things...anyway a function like this: function createTag(tagStr) { var div = document.getElementById("createElement"); div.innerHTML = tagStr; return createElement.firstChild; } The advantage in this being that most of the work is done by the browser, with little code. You just append the tag where you want it. However, as mentioned, I have not fully tested this for browser compatability. Woops…accidently pressed things…anyway a function like this:

function createTag(tagStr) {
var div = document.getElementById(”createElement”);
div.innerHTML = tagStr;
return createElement.firstChild;
}

The advantage in this being that most of the work is done by the browser, with little code. You just append the tag where you want it. However, as mentioned, I have not fully tested this for browser compatability.

]]>
By: MillsJROSS http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12083 MillsJROSS Wed, 16 Apr 2008 13:13:06 +0000 http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12083 Woops again... return div.firstChild; or return div.firstChild.cloneNode(true); Sorry for the triple post. Woops again…

return div.firstChild;

or

return div.firstChild.cloneNode(true);

Sorry for the triple post.

]]>
By: Anonymous http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12838 Anonymous Sun, 20 Apr 2008 14:46:20 +0000 http://mattsnider.com/languages/javascript/document-createtag-method/#comment-12838 "The switch statement then, normalizes the keys, so the key ‘checked’ does the same thing as ‘cHeCkEd’, because capitalization does matter." switch (k.toLowerCase()) { ... case ‘checked’: case ‘disabled’: node[k] = v; break; Would that not be bad, as 'ChEcKed' would be caught, but the assignment would end up being node['ChEcKed'] = v; which, as far as I'm aware, would fail? “The switch statement then, normalizes the keys, so the key ‘checked’ does the same thing as ‘cHeCkEd’, because capitalization does matter.”

switch (k.toLowerCase()) {

case ‘checked’:
case ‘disabled’:
node[k] = v;
break;

Would that not be bad, as ‘ChEcKed’ would be caught, but the assignment would end up being node[’ChEcKed’] = v; which, as far as I’m aware, would fail?

]]>
By: Matt Snider http://mattsnider.com/languages/javascript/document-createtag-method/#comment-13551 Matt Snider Sun, 27 Apr 2008 18:01:11 +0000 http://mattsnider.com/languages/javascript/document-createtag-method/#comment-13551 You are correct. The variable k should be lower-cased after fetching the value from the hash. I have updated the script above to reflect this change. You are correct. The variable k should be lower-cased after fetching the value from the hash. I have updated the script above to reflect this change.

]]>