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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:30:51+00:00 2026-06-13T13:30:51+00:00

I am attempting to create a script that allows the user to click a

  • 0

I am attempting to create a script that allows the user to click a div element with an h1‘d bit of text and then replace the h1 with a textbox and a graphic to click after editing. Once the graphic is clicked, the div will replace the textbox and graphic with the newly edited h1‘d bit of text.

Here are the functions:

function savename() {
    var s = $('#mytextbox').val();
    $('#mydiv').replaceWith('<div id="mydiv" onclick="editname();"><h1>' + s + '</h1></div>');
}
function editname() {
    var strName = $('#mydiv').text();
    $('#mydiv').replaceWith($('<div id="mydiv"><input id="mytextbox" name="mytextbox" type="text" value="' + strName + '"><img id="mysavebutton" src="images/save.gif" onclick="savename();"></div>'));
}

And here is the div:

<div id="mydiv" onclick="editname();"><h1>Some text I want to edit</h1></div>

So, the div click function works fine. It replaces the h1 element with a textbox. And when I click the save graphic, that works fine too, in that it returns the h1. The problem is, the value of the textbox is supposed to be the h1‘d text. That part’s not working. It still retains the old value. I put an alert for “s” after setting it to .val() and it still shows the old value, even after editing. I feel like I’m missing something simple, but I’ve fought with it all day and need some fresh eyes to look at it for me. Thanks in advance.

  • 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-13T13:30:53+00:00Added an answer on June 13, 2026 at 1:30 pm

    Instead of replacing the mydiv and trying to re-creating mydiv, why don’t you just hide mydiv on click and change the value of the h1 tag when you try to save?

    In the html you can have something like this:

    <div id="mydiv">
        <h1 id="myoutput" onclick="editname();"> ... </h1>
        <input id="mytextbox" name="mytextbox" type="text" style="display:none;">
        <img id="mysavebutton" src="images/save.gif" onclick="savename();" style="display:none" /> 
    </div>
    

    Then in javascript:

    function editname()
    {
        var s = $('#myoutput').text();
        $('#myoutput').css('display', 'none');
        $('#mytextbox').val(s).css('display','inline');
        $('#mysavebutton').css('display', 'inline');
    }
    function savename()
    {
        var s = $('#mytextbox').val();
        $('#myoutput').text(s).css('display', 'inline');
        $('#mytextbox').css('display', 'none');
        $('#mysavebutton').css('display', 'none');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create an automated bash script that fills up a file with
I'm attempting to create a postcode lookup JQuery script that'll be able to be
I am attempting to create a top-level script that will call about 35+ other
I'm attempting to create an ASP.NET/C# page that runs a PowerShell script that will
I'm attempting to create a simple backbone view that attaches to an <li> element.
I'm attempting to create a map that allows users to report a trailwork problem
I am attempting to create a script that wraps a Groovy class that will
I am currently attempting to create a bash script that will check inside of
I am attempting to create a Python script that in turn runs the shell
So I'm attempting to create a simple Ruby script that removes a specified number

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.