Posted By

elightbo on 01/17/07


Tagged

javascript DOM


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

nicolaspar
markireland
shachi
vali29


Javascript DOM


 / Published in: JavaScript
 

A few functions to handle DOM events (firstChild, nextSibling, firstSibling, lastSibling)

Accounts for firefox treating /n as a node.

  1. //dom javascript functions
  2. function firstChild(startParent){
  3. var tempObj = startParent.firstChild;
  4. while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
  5. tempObj = tempObj.nextSibling;
  6. }
  7. return (tempObj.nodeType==1)?tempObj:false;
  8. }
  9. function nextSibling(startBrother){
  10. var tempObj = startBrother.nextSibling;
  11. while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
  12. tempObj = tempObj.nextSibling;
  13. }
  14. return (tempObj.nodeType==1)?tempObj:false;
  15. }
  16. function firstSibling(node){
  17. var tempObj=node.parentNode.firstChild;
  18. while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
  19. tempObj=tempObj.nextSibling;
  20. }
  21. return (tempObj.nodeType==1)?tempObj:false;
  22. }
  23. function lastSibling(node){
  24. var tempObj=node.parentNode.lastChild;
  25. while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
  26. tempObj=tempObj.previousSibling;
  27. }
  28. return (tempObj.nodeType==1)?tempObj:false;
  29. }

Report this snippet  

You need to login to post a comment.