Find text nodes using jquery? -


i found how select text nodes jquery? problem although can go like

$(elem)   .contents()   .filter(function() {     return this.nodetype == node.text_node;   }).each(function() {      this.nodevalue = //stuff   }); 

i trying figure out how can combine this.nodetype before , after nodes because of stuff need can appear combination of this.nodevalue + before, this.nodevalue or this.nodevalue + after if makes sense , need test each node value in combination previous , next ?

if understood correctly, wanted prev , next node when hit text node. see below,

var elcontents = $('#test').contents(); elcontents.each(function(idx, el) {     if (el.nodetype == 3) {         if (idx == 0) {            prev = null;            next = elcontents.get(idx + 1);         } else if (idx == elcontents.length - 1) {            prev = elcontents.get(idx - 1);            next = null;         } else {            next = elcontents.get(idx + 1);            prev = elcontents.get(idx - 1);         }          //below demo code         $('#result').append ("<b>prev: </b>" + $(prev).text() + " <b>cur: </b>" + $(el).text() + "<b> next: </b>" + $(next).text() + '<br />');     } }); 

demo: http://jsfiddle.net/sfmrr/

note: in demo, elements inside div doesn't have additional space/line breaks because when iterate on contents() includes line breaks , space textnode.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -