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 3307582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:25:22+00:00 2026-05-17T21:25:22+00:00

Here is my code: <li class=det_price> <a href=/designer/customize/278258?dpid=1>Printing</a> from $10 </li> I have about

  • 0

Here is my code:

<li class="det_price">
    <a href="/designer/customize/278258?dpid=1">Printing</a> from $10 
</li>

I have about fifteen chunks like this on any given page, and I’d like to take the text node (from $X), select X using a regular expression and set it to a numeric variable, then multiply it by a %, and append it to the original node. For example, if the original node said “from $10” I would like to replace it with “from $10 to $2.60”. I can do this using replace() and regular expressions on a single node, but I’m having trouble iterating through all of them with jQuery. Can I apply such a transformation to a jQuery object, or do I need to convert it somehow and then use standard Javascript functions?

Thanks!

  • 1 1 Answer
  • 3 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-05-17T21:25:23+00:00Added an answer on May 17, 2026 at 9:25 pm

    Here’s how to select a text node.

    Here’s (the skeleton of) what you do once you’ve got ’em:

    $('li.det_price').contents().filter(function()
    { 
        return this.nodeType == 3;
    }).text(function (i, text)
    {
        return text.replace(/* your schtuff here */);
    });
    

    So apparently jQuery doesn’t play that nicely with text nodes

    Time to get (a little) hacky:

    var rnotwhite = /\S/; // to omit text nodes that are solely white space
                          // tweak this as needed
    $('li.det_price').contents().filter(function()
    { 
        return this.nodeType === 3 && rnotwhite.test($(this).text());
    }).text(function (i, text)
    {
        this.replaceWholeText(text + ' replaced');
        // or, for more cross-browser-ness
        // this.nodeValue = text + ' replaced';
    });
    

    --> Check out this sweet demo <--

    --> IE-compatible demo here <--

    Now here’s the deal: if you have control of the markup, the best solution for this is to wrap the text nodes you’re actually interested in, in <span>s, like this:

    <li class="det_price">
      <a href="/designer/customize/278258?dpid=1">Printing</a><span> from $10</span>
    </li>
    

    and then you can just do this (way less sketch, IMO):

    $('li.det_price > a + span').text(function (i, text)
    {
        return text + ' replaced';
    });
    

    --> More demo goodness <--

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

Sidebar

Related Questions

I have a problem with list within a class in python. Here's my code
Suppose I have following code: public class CBase: AbstractC,IRenderable { //code here } public
Can a DateTime value be NULL ? I have this code: From here I
Here is my code: class MyTestCase(Base): def setUp(self): #some code here def test_B(self): #some
Here is code example class A{ int i; public: A(int i) : i(i) {}
Here is the code: class Class1 { private Class2 object; public Class1(Class2 obj) :
Here is some code: class Person def initialize(age) @age = age end def age
Here's the code: class qual { public static int fibonacci(int n) { if (n
Here is the code: class Time { public static void printTime (int hour, int
Here is my code: class Soldier { public: Soldier(const string &name, const Gun &gun);

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.