By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Returning "null" or "false" if nextSibling doesn't exist

P: 127
Hi all,

I have a routine that checks to see if an ID has been set for the next row down in a table. Everything works fine except if I'm on the last row and no row exists; the routine just hangs:

Expand|Select|Wrap|Line Numbers
  1. var checkNext =;
Any ideas how I can get this to return "null" or "false" is there isn't a subsequent row in the table?

Many thanks in advance!
Jul 25 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 8,639
you can test for the next sibling first
Expand|Select|Wrap|Line Numbers
  1. if (obj.parentNode.parentNode.nextSibling)
  2. // or
  3. if ("undefined" == typeof obj.parentNode.parentNode.nextSibling)
Jul 25 '09 #2

P: 127
Works like a charm!


Jul 25 '09 #3

Expert Mod 5K+
P: 8,639
you could do even more...
Expand|Select|Wrap|Line Numbers
  1. if (sibl = obj.parentNode.parentNode.nextSibling)
  2. {
  3.     var checkNext =;
  4. }
  5. // ...
Jul 25 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.