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

  • Home
  • SEARCH
  • 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 8888821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:06:59+00:00 2026-06-14T22:06:59+00:00

Trying to understand something here: if I render something to the DOM from javascript,

  • 0

Trying to understand something here: if I render something to the DOM from javascript, and want to call jQuery methods on it, it behaves differently than if I “re-select” the element from the DOM. Here’s a simple example, in CoffeeScript:

element = """
  <div id="my_div">TEST!</div>
  """

$('body').html(element)
element.hide() #this doesn't work.
$(element).hide() #this doesn't work either.

$('div#my_div').hide() #this does.

So, I seem to be misunderstanding something here. I guess the element variable is just a string and jQuery doesn’t understand that it has been added as an element in the DOM.

Is there a different way to insert content into the dom, then, so that it behaves like a normally-selected jQuery object once it has been inserted?

  • 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-14T22:07:00+00:00Added an answer on June 14, 2026 at 10:07 pm

    The reason the first line doesn’t work is because element is a string. The reason the second line doesn’t work is because it ends up creating another DOM version of the string.

    The fix would be to maintain a ref to the DOM version of the element the first time you construct it (in JS):

    var $elem = $(element);
    $elem.appendTo(document.body);
    $elem.hide() // should work
    

    Hope that helps.

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

Sidebar

Related Questions

I'm trying to understand why javascript is doing something unexpected (to me). Here's a
I'm trying to understand the tspan tag in svg and here is something weird.
Trying to understand something. I created a d:\svn\repository on my server. I committed folders
I'm trying to understand on a deeper level if I'm missing something as to
I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something
I'm trying to understand REST. Under REST a GET must not trigger something transactional
I'm trying to learn MVVM, but there is something I don't understand yet. Currently,
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
I'm trying to get data from textbox but it says undefined id or something
I am trying to understand something a bit better with being new to C#,

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.