kurt.santo Posted October 11, 2007 Share Posted October 11, 2007 Working my way through a very long code I wondered if someone could look at my comments to help me with my open question and see if my comments show that I understood the whole thing correctlly. I have to change certain bits of the code, but do not want to attempt to do so before I understand each bit of where it does what... lastSibling:function(node){ //go to parent of relevant node and find last child of parent node var tempObj=node.parentNode.lastChild; //nodeType!=1 I do not understand. what does "1" stand for? //the second test checks that there is a previous sibling while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){ //when both tests return true, store the previous sibling of the the last child of parent node in tempObj tempObj=tempObj.previousSibling; } //otherwise (while is not true) test if nodeType of the tempObj is 1 and if yes, set it to the tempObj, otherwise return false return (tempObj.nodeType==1)?tempObj:false; } Also, I bought this amazing book with many good examples and would like to share some great codes with you (they are all from a book by Christian Heilman). Is this allowed? And if yes, should I post them here or post here a link with the location of where I put them (might be next week then as we are just in process of buying web space/ domain)?Kurt Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2007 Share Posted October 11, 2007 In XML, the word "node" encompasses anything you can find in a document. Much like "token" in programming languages.A node refers to elements, attributes, text, processing instructions, comments and documents themselves.The nodeType property shows which one of those type of nodes you're dealing with. I'm not sure about what the complete list is, but I know 9 stands for document node and 1 stands for element node.So, tempObj.nodeType!=1 stands for "if the node is any other than element node". //otherwise (while is not true) You're wrong here. The following test will be applied with or without the previous loop ever executing. That's pretty much the reason there is a test(tempObj.nodeType==1) here to begin with. and if yes, set it to the tempObj If you mean "return tempObj" - yes. Link to comment Share on other sites More sharing options...
kurt.santo Posted October 11, 2007 Author Share Posted October 11, 2007 With an element node being a html tag as <li> or <td> for example?Thank you for your input!Kurt Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2007 Share Posted October 11, 2007 With an element node being a html tag as <li> or <td> for example?Yes. The only difference between "element" and "tag" being that "tag" refers to the opening ("<li>") or closing ("</li>") part of an element (The opening and closing tags combined). Link to comment Share on other sites More sharing options...
justsomeguy Posted October 11, 2007 Share Posted October 11, 2007 Here's a list of the node types:http://developer.mozilla.org/en/docs/DOM:element.nodeType Link to comment Share on other sites More sharing options...
kurt.santo Posted October 13, 2007 Author Share Posted October 13, 2007 Thanks to all:-) Just to doble-check on boen_robot's comment:Tag can be either the opening and closing tag (ok, got this one) and element refers to opening and closing tag as a unit as such???Kurt Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2007 Share Posted October 15, 2007 The element is the object inside the DOM that is represented by the tag(s) on the page. Tags like this:<a href="java script:void(0);">Click</a>will be responsible for having an anchor element created in the DOM with the given href and child node (the "click" text is a text node that is a child of the anchor node). I'm using the terms "node" and "element" interchangeably. The tag is just the code representation of the object in the DOM, or the object in the DOM is the object representation of the code on the page. Link to comment Share on other sites More sharing options...
kurt.santo Posted October 15, 2007 Author Share Posted October 15, 2007 The element is the object inside the DOM that is represented by the tag(s) on the page. Tags like this:<a href="java script:void(0);">Click</a>will be responsible for having an anchor element created in the DOM with the given href and child node (the "click" text is a text node that is a child of the anchor node). I'm using the terms "node" and "element" interchangeably. The tag is just the code representation of the object in the DOM, or the object in the DOM is the object representation of the code on the page.Thank you for your feedback...Kurt Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.