Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:51:35+00:00 2026-06-05T02:51:35+00:00

I found How do I select text nodes with jQuery? but my problem is

  • 0

I found How do I select text nodes with jQuery? but my problem is that although I can go like

$(elem)
  .contents()
  .filter(function() {
    return this.nodeType == Node.TEXT_NODE;
  }).each(function() {
     this.nodeValue = //stuff
  });

I am trying to figure out how I can combine this.nodeType with the before and after nodes because some of the stuff I need can appear as a combination of the this.nodeValue + before, this.nodeValue or this.nodeValue + after if that makes sense and I need to test EACH node value as well as it in combination with the previous and next ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:51:37+00:00Added an answer on June 5, 2026 at 2:51 am

    If I understood correctly, you wanted to get the prev and next node when you hit the 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 is 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 the demo, the elements inside div doesn’t have any additional space/line breaks because when you iterate over contents() It includes line breaks and space as textNode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to delete all the rows found by that query: SELECT cart_abandon.*
I'm using XAMPP Lite - USB Version and found that the jQuery chained select
In jQuery I'm trying to select only mount nodes where a and b's text
a want that, he found all select elements with id than begins with 'chbTypes'
I found something like this in a SqlServer DB stored proc: SELECT stuff FROM
My SQL statement looks like that SELECT SQL_CALC_FOUND_ROWS q.id, q.question, sb.subject, c.chapter, sc.section, p.paragraph
I'm having trouble grouping a set of nodes. I've found an article that does
This things works perfectly <select name=selectbox onchange=alert(this.value)> But I want to select the text.
I think I have a very popular problem, but not found answer for it
So I've got some <select> tags that I would like to show the entire

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.