Posted By

jatkins on 07/19/11


Tagged

element html DOM


Versions (?)

previousElement and nextElement


 / Published in: JavaScript
 

Released into the public domain. I haven't tested these (realized I didn't need them for what I was trying to do), but they should work. Bug fixed 7/19/2011.

  1. function previousElement(elmnt) {
  2. elmnt = elmnt.previousSibling;
  3. while(elmnt&&elmnt.nodeType!=1)
  4. elmnt = elmnt.previousSibling;
  5. return elmnt;
  6. }
  7.  
  8. function nextElement(elmnt) {
  9. elmnt = elmnt.nextSibling;
  10. while(elmnt&&elmnt.nodeType!=1)
  11. elmnt = elmnt.nextSibling;
  12. return elmnt;
  13. }

Report this snippet  

You need to login to post a comment.