Find Element Position


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.