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

  • Home
  • SEARCH
  • 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 4535696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:26:17+00:00 2026-05-21T14:26:17+00:00

I am new to jquery, and I’m having trouble doing what I thought should

  • 0

I am new to jquery, and I’m having trouble doing what I thought should be a very simple find and replace operation.

I want to change the text inside the the “<p>” tags. So for instance I might want to replace “your title” with “a title“.

  <div id="ValidationSummary">
    <ul>
        <li>
            <p>
                Please specify your title</p>
        </li>
        <li>
            <p>
                Please enter your first name</p>
        </li>
        <li>
            <p>
                Please enter your surname</p>
        </li>
    </ul>
    </div>

and here is the jQuery which isn’t doing anything:

$(function() {
    $('#ValidationSummary').text().replace("your title", "a title");
    $('#ValidationSummary').text().replace("first name", "christian name");
    $('#ValidationSummary').text().replace("your surname", "your last name");
};

I really cannot see what I’m doing wrong, any ideas?

Please help, thanks

  • 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-21T14:26:18+00:00Added an answer on May 21, 2026 at 2:26 pm

    Any changes to strings in JS always produces a new string, rather than modifying what was there. Fortunately jQuery makes it easy to both retrieve and modify text at the same time:

    $('#ValidationSummary p').text(function (i, old) {
         return old
             .replace('your title', 'a title')
             .replace('first name', 'christian name')
             .replace('your surname', 'your last name');
    });
    

    Explanation:

    • returning a string from .text() tells jQuery to replace what was there (passed in as old) with this new string.

    • Since replace() returns a new string each time, we can chain multiple calls together, so that we only need one .text() call and return statement.

    • I used the selector '#ValidationSummary p' since using .text() or .html() will replace the entire contents of the element it is operating on.

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

Sidebar

Related Questions

I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
I am having trouble learning to use the new jQuery Deferred. The does an
I new with jquery and I can do simple coding with it. and I
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Im new in jQuery so sure that i am doing something wrong :(. Matter
I was going through the source code of jQuery. I'm having trouble understanding the
Fairly new to jquery so I might be making a simple mistake but I
I am new jquery mobile. i want to use showPageLoadingMsg() of jquery mobile.But it
When writing a new jQuery plugin is there a straightforward way of checking that
Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to

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.