Posted By

tclancy on 03/03/09


Tagged


Versions (?)

Find Element Position


 / Published in: JavaScript
 

  1. function getPosition(main,spec) {
  2. var items = main.getElementsByTagName(spec.tagName);
  3. var found = 0;
  4. for (p = 0; p < items.length; p++) {
  5. if (items[p] == spec) {
  6. found = 1;
  7. break;
  8. }
  9. }
  10. if (found) {
  11. return p;
  12. }
  13. else {
  14. return -1;
  15. }
  16. }

Report this snippet  

You need to login to post a comment.