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

100+
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 = obj.parentNode.parentNode.nextSibling.id;
  2.  
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


Dormilich
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

100+
P: 127
Works like a charm!

Thanks!

@Dormilich
Jul 25 '09 #3

Dormilich
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 = sibl.id;
  4. }
  5. // ...
Jul 25 '09 #4

Post your reply

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