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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:05:23+00:00 2026-06-08T20:05:23+00:00

So I have this div with a field ( input[type=text] ) inside it and

  • 0

So I have this div with a field (input[type=text]) inside it and I’m creating a copy of this div’s contents and displaying the copy to the user to edit it’s value. When they update the copy’s value it’s then submitted which changes the value of the original.

The problem is that when I delete the copy and make a new copy from the hidden div again the text appearing in the field of the new copy is the original text (when the page loaded) and not the new text that it was updated to. The original field shows the new text inside it, but when I inspect element on it, the value attribute shows the old text.

In other words everything is correct except the text showing up in the copies and the value attribute of the original.

So I’m wondering if I’m doing something wrong or if there’s some kind of work-around.

Here’s a code example:

<div style="display:none">
    <input type="text" value="test" />
    <a>Submit</a>
</div>
<button class="get">Get value</button>
<button class="show">Show hidden one</button>
<button class="copy">Copy hidden one</button>​
$('button.copy').click(function(){
    $('<br><span>'+$('div').html()+'</span>').appendTo('body');
});

$('a').live('click',function(){
    $('div input').val($('span input').val());
    $('span').remove();
});

$('button.get').click(function(){
    alert($('div input').val());
});

$('button.show').click(function(){
    $('div').show();
});

​My jsFiddle

  • 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-08T20:05:25+00:00Added an answer on June 8, 2026 at 8:05 pm

    .val() doesn’t update the value attribute, so when you do .html() or inspect element you are seeing the original html and not the value. If you change one line of your code above to:

    $('div input').attr("value", $('span input').val());
    

    It should work as you are expecting it to. I have seen similar issues with .data() when trying to set a data-attribute with .data then retrieve it with .attr("data-

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

Sidebar

Related Questions

I have this javascript/ jquery to list available users. HTML: <input name=username type=text size=16
I have a type ahead text field, and when the user hits Enter I
I have this div inside a repeater, where i set the class, onmouseover and
I have this div in my code: <div id=advice class=validation-advice style=>some text here</div> Now,
i have text like this div bla-bla end div i need to get only
i have this schema: <div id=container> <div id=content>some text</div> <footer> my footer things </footer>
I have a text field. When I type something into than text field, I
<form id=youtube-form method=post action=> <label for=searchField id=label-youtube-id>YouTube ID:</label> <input type=text id=searchField name=videoid class=search-field />
I have a website design that includes text input fields that look like this:
I have form like this : <div id='add_field' class='locbutton'><a href='#' title='Add'>Add</a></div> <div id='remove_field' class='locbutton2'><a

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.