Related Post

9 Comments Received

June 6th, 2007 @11:01 am  

Hey this is just what I was looking for. Thanks :)

November 3rd, 2007 @7:13 am  

Thanks buddy…

I tried the code but to make it run I had to put 1 as String

function getNextSibling(startBrother){
endBrother=startBrother.nextSibling;
while(endBrother.nodeType!=”1″){
endBrother = endBrother.nextSibling;
}
return endBrother;
}

November 3rd, 2007 @7:14 am  

My Firefox version is 2.0.0.9

November 11th, 2007 @6:21 am  

the problem with this code starts when the
startBrother.nextSibling = empty space, which in ie you can check it with “if(startBrother.nextSibling)” but with firefox there’s a bit of complex.. didn’t find the answer yet…

May 26th, 2008 @4:18 am  

Just exploring some Javascript stuff. LOL, I accidently copied the code in comments, so it works. Same code works for previousSibling, only u have to chande the nextSibling to previousSibling. Great work!

Thanks.

October 27th, 2008 @9:42 pm  

so cool.. I like it. thanks.

September 18th, 2009 @2:01 am  

I didn’t like that if the element doesn’t have a sibling, then the code errors out :/

I changed the code to check this (and also changed it so it gets the next node of the same type)

function getNextSibling(startBrother) {
endBrother = startBrother.nextSibling;
while (endBrother && endBrother.nodeName != startBrother.nodeName) {
endBrother = endBrother.nextSibling;
}
if (!endBrother) {
return false;
}
return endBrother;
}

use it like this:

if (getNextSibling(el)) {
[//CODE//]
}

November 13th, 2009 @7:21 am  

I’m experiencing extra spaces in firefox 3.5.5 when using the jquery hide function to hide divs when they are empty. I’m pretty sure this is what i need but i have no idea how to implement it with the jquery hide function and am hoping someone might be able to help. Below is my jquery code:

$(document).ready(function () {

$(’.show’).each(function() {
if ($(this).text() == “”) {
$(this).hide();
};
});
});

////The html is:




////end html

I did eliminate all spaces between divs and it did eliminate the spaces in output but it makes the code not human-readable friendly which i would like.

Thanks for any help! :)

November 13th, 2009 @7:23 am  

oops – i guess i can’t place the html? – basically it’s
a number of divs with the class “show” in a table.

Leave A Reply

Please Note: Comments maybe under moderation after you submit your comments so there is no need to resubmit your comment again