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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:46:23+00:00 2026-05-30T12:46:23+00:00

html file: <div id =main> </div> Javascript: //create a div var divElem = $(‘<div

  • 0

html file:

  <div id ="main">
  </div>

Javascript:

//create a div
var divElem = $('<div class="divText"></div>');

//create input element inside it
var inhtml = "<input type='text' id='12345' />";

//add to page
$(divElem).html(inhtml).appendTo('#main')

Following does not work as it is unable to find input element:

//retrieve input element
$('#12345').val('hello')

Following works:

document.getElementById('12345').value = 'hello'

Following works:

var ipElem = $(inhtml);
$(divElem).append(ipElem).appendTo('#main')
$(ipElem).val('hello')

Can anyone tell why first version of retrieving element does not work in jquery? (just starting with jquery… 🙂 )

Edit:
I think ‘12345’ works but not some weird id like: mytext0.15942923246580176
See here:
http://jsfiddle.net/9PVNb/4/

  • 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-30T12:46:24+00:00Added an answer on May 30, 2026 at 12:46 pm

    You’re wrapping divElem in jQuery object twice:

    var divElem = $('<div class="divText"></div>');
    var inhtml = "<input type='text' id='12345' />";
    
    $(divElem).html(inhtml).appendTo('#main') // Nop '$(divElem)' plus missing `;`
    divElem.append(inhtml).appendTo('#main'); // Yup
    

    EDIT:

    Edit: I think ‘12345’ works but not some weird id like: mytext0.15942923246580176

    Your code at http://jsfiddle.net/9PVNb/4/ isn’t working because:

    // Your `id` has a `.` which you didn't escape
    var elemid = 'mytext0.15942923246580176';
    

    You can make it work by doing this:

    alert($('#' + elemid).val()); //undefined. DOES NOT WORK
    alert($('#' + elemid.replace('.', '\\.')).val()); // hello world IT WORKS!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this files: JAVASCRIPT $(document).ready(function(){ $('a').click(function(){ $('div').load(formular.html,function(){ $('input[type=submit]').click(function(){ $('form').submit(); }); }); }); });
it must be jquery I have file text.html with 6 div in (a,b,c,d,e,f) In
I have the following code in my file to load a div with HTML
I am trying to basically call a function from another javascript file (inside a
I have a working webpage which just displays external html files inside a div
<div id='main'> <fieldset> <legend>Feed</legend> <div class='user_show_finds'> <span> <h3> product name </h3> <p> <a href=/products/1>Thorpe
I am trying to output from a Javascript file to the HTML page, and
I am using php. Create a file leftcolumn.php which includes following codes.. <!DOCTYPE html
Given a HTML file with the structure html -> body -> a bunch of
I have a HTML file that has code similar to the following. <table> <tr>

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.