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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:35:35+00:00 2026-05-13T15:35:35+00:00

Using the following code var newDiv = $(document.createElement(div)); var newTextBox; newTextBox = $(document.createElement(input)) .attr(type,

  • 0

Using the following code

var newDiv = $(document.createElement("div"));
var newTextBox;

newTextBox = $(document.createElement("input"))
    .attr("type", "text")
    .attr("id", "textbox")
    .attr("name", "textbox");

newTextBox.val("text");
newDiv.append(newTextBox);
alert(newDiv.html());

I get the following

<input name="textbox" id="textbox" type="text">

I get the same thing with

$("#textbox").val("test");

Using

newTextBox = $("<input/>");

Doesn’t help either

Where is my value?

EDIT: SOLTUION

So, further up in the stack I was converting the DOM I built to a string and since – like munch mentioned – the dynamic value doesn’t get added to the tag, it wasn’t showing up.

Thanks for the help

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

    jQuery will not put the value into the created element’s generated html. Both .attr('value', 'blah') and .val() get the current value of what’s been entered or changed in the text input, and allow you to see that value when you look at the input on the page or submit it to the server. However, you will not see it when looking at the html.

    You can still manipulate the value all you want, you just won’t see any changes in firebug, like you do with class changes, styling, etc.

    AFAIK, this is the same without using jQuery. The same thing happens with:

    document.getElementById('textbox').value = 'my text'; 
    

    The value attribute is only to set something’s value from the server. It’s not needed with javascript.

    Also, it depends on the type of input that you’re using. For example, you will see the value attribute changes with a hidden input, but not with the textbox.

    EDIT:

    By appending newDiv to the body, the text box and the value show up using your code. Here’s a test page. You can see both the code and the preview of what happens. The alert though, does not show any ‘value’ attribute for reasons explained above.

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

Sidebar

Related Questions

Using the following code: <script type=text/javascript> function moveFront(el){ var me = $('#'+el.closest('div').attr('id')); var parent
I'm using the following code.. $(document).ready(function(){ $(#test a).click(function(){ var labelTo = $(this).text(); window.location =
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I am using the following code function xhi(aax) { var aby=document.getElementById(aax); aby.style.bottom=(parseInt(aby.style.bottom)+(screen.height-42)/10)+'px'; if(parseInt(aby.style.bottom)<(screen.height-42))setTimeout('xhi('+aax+')',25); }
I am using jQuery UI 1.8 and have the following code: var newDiv =
I am using the following JavaScript code: var a = [23, 34, 45, 33];
I am using ASP.NET 3.5 with iTextSharp and I have the following code: var
I am using the following code to submit different values var evalue= 'color:#d32;font-size:12px;'; jQuery.ajax({
I'm using the following code to retrieve a json string from my webserver: var
I am using the following code to generate an encrypted token: var ticket =

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.