I need to have a way to find the next/prev node, be it a sibling, child, or text node. For example:
<code> <p> (1) Some simple text <span class='nextTextNode'>that</span>'s special. (2) And find next Sibling <span class='nextSibling'>sib1</ span><span>sib2</span> (3) Finally a child node <span class='nextChildNode'>Parent<span class='childNode'>Child</span></ span> </p> </code> It isn't hard to get these options if you knew what you were selecting, but in my case users will be selecting the html and it could be anything. Is there anyway to find the very next node? My current thought process, is to get the p tag in this example and pull the contents into an array. But I don't think this is very efficient. A proof of concept is the following code, I would think I'd need to make this a recursive function, but I don't think this is the right approach. $('p').contents().each(function(){ if(this.nodeType == 1){// recursive would occur here $(this).contents().each(function(){ console.log(this); }); } else{ console.log(this); } }) Any suggestions that can point me in the right direction would be very helpful. Jeremy