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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:01:14+00:00 2026-05-30T18:01:14+00:00

I would like to use JQuery to reorder all data that contains a certain

  • 0

I would like to use JQuery to reorder all data that contains a certain word.The .find() framework works on elements as far as I can tell and not on items within the string.

The data is currently arranged like this:

    <div>A single zones 1,2 and 3 Tube ticket to £2.20</div>
<div>A single zones 1,2 and 4 Bus ticket to £2.20</div>
<div>A zones 1,2 and 3 Ferry ticket to £2.20</div>

I want to find if the DIV has the word ‘single’ in it and move it in after the zone data so that the ticket type reflects if it is single.

<script type="text/javascript">
    $(document).ready(function(){
        $('div').each(function(){
            if($(this).find('single')) {  };
        });
    });
</script>

I have got thus far. Obviously though that is not going to work. Any ideas?

EDIT this is what I would like the outcome to be:

<div>A zones 1,2 and 3 single Tube ticket to £2.20</div>
    <div>A zones 1,2 and 4 single Bus ticket to £2.20</div>
    <div>A zones 1,2 and 3 Ferry ticket to £2.20</div>
  • 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-05-30T18:01:15+00:00Added an answer on May 30, 2026 at 6:01 pm

    You can do something like this:

    ​$("div:contains(single)").html(function(i,currentVal) {
       return currentVal.replace(/single /,"")
                        .replace(/ (Tube|Bus|Ferry)/," single $1");
    });​​​​​​​​​​​​​​​
    

    Demo: http://jsfiddle.net/nnnnnn/R3V63/

    This uses the ":contains" selector to find all divs that have the word “single”, and then uses the .html() method with the callback syntax that lets the individual values be processed one at a time where the supplied callback function will be passed the current html contents of each element and the return value becomes the new content.

    To “move” the word “single” I’m first replacing it with an empty string, and then inserting it immediately before any of the words “Tube”, “Bus” or “Ferry”. Obviously if there is some other mode(s) of transport to be included the regex can be amended. Trying to find the right spot by matching on “Zones 1, 2 and 3” seemed too much hassle given the possible variations like “Zone 1”, “Zones 2 and 3”, etc.

    See the doco on .replace() for more information.

    EDIT: alternate regex to match on “Zones …” (not so much hassle after all):

    .replace(/(zones?(?:[\d, ]|and)+) /,"$1 single ");
    

    (seems to work fine: http://jsfiddle.net/nnnnnn/R3V63/4/)

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

Sidebar

Related Questions

I would like to .get a page and then use jquery to find elements
I would like to use Jquery to add a class to li element that
I would like to use jquery to remove some tags inside mainclass, so that
i would like to use jquery ui selectmenu from felixnagel. it works but i
Hello I would like to use jQuery to wrap sets of elements in a
I would like to know how can I use jQuery to select multiple items
I am relatively new to using jQuery and would like to use the load
I would like to know if I can use the following JQuery function on
I would like to use a language that I am familiar with - Java,
I would like to use a component that exposes the datasource property, but instead

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.