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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:48:51+00:00 2026-05-31T15:48:51+00:00

We came across the following situation while trying to make changes to a web

  • 0

We came across the following situation while trying to make changes to a web page.

<div id="div1">
   Welcome <button id="clicker">Click Me</button>
</div>

This of course is just a basic example of what we ran into. All we want to do is change the text of the div without losing the button. For example, instead of Welcome, we’d like it to say Hi.

Is there a simple way to accomplish this with jQuery? I’ve tried using .replace but that didn’t seem to work.

$("#div1").text().replace("Welcome", "Hi");

Update

Thank you everybody for such a quick response and great answers. Responses from gdoron and mblase75 worked great. For simplicity, mblase75 seemed to be the easist to implement but gdoron went out of his way to explain line by line. Thank you again so much!

  • 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-31T15:48:53+00:00Added an answer on May 31, 2026 at 3:48 pm

    One approach would be to use the callback function for .html:

    $('#div1').html(function(i,old) {
        return old.replace('Welcome','hi');
    });
    

    http://jsfiddle.net/VsAZu/

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

Sidebar

Related Questions

I came across the following code while debugging. I was able to get the
I came across the following tutorial JSP tricks to make templating easier? for using
I came across this situation where the following plinq statement inside static constructor gets
I'm trying to understand the basic of WCF, when I came across following question:
I came across a weird situation when trying to count the number of rows
I came across the following while reading about how easy it is to redefine
I came across the following markup in a JSP file in a legacy app
I came across the following expression in someone else's code. I think it's terrible
I came across the following regular expression below on one of my code, anyone
I came across the following code that compiles fine (using Visual Studio 2005): SomeObject

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.