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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:41:10+00:00 2026-06-11T13:41:10+00:00

I have a pair of HTMLElement objects that are being passed into a function.

  • 0

I have a pair of HTMLElement objects that are being passed into a function. One is a container div, and the second is appended to the container. This is working as expected. In order to find the child element later, i give it a unique class for this type of element (there can be more than one). This is also working as expected.
However, when I later go to manipulate the child element, jQuery .find(“.myClass”) fails to return any results. The following code returns 1 in chrome and ie8/9 but 0 in ie7:

$(document).ready(function(){
    var insert = document.createElement("div");
    insert.setAttribute("class","insertedElement");
    insert.appendChild(document.createTextNode("Some Text"));
    $(document.getElementById("container")).append(insert);
    alert($("#container").find(".insertedElement").length);
});

Here it is in a JSFiddle: http://jsfiddle.net/tYfqk/

Any idea what is happening here, or how i can correct it?

Also, please excuse the contrived $(“document.getElementById(“container”)).append(insert); above, this is just to illustrate that my objects come in as DOM elements, not jQuery objects. I am aware $(“#container”).append(insert); would make more sense there, but even if you change that the issue is still present.

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

    Old versions of IE won’t let you set the class by setting the “class” as an attribute. Use the jQuery “addClass” instead.

    $(insert).addClass("insertedElement");
    

    Or just set the “className” property:

    insert.className = "insertedElement";
    

    (The word “class” is reserved in JavaScript, so the property is “className”.) In general, things like “className”, “id”, “name”, “value”, “type”, “href”, etc on DOM elements can and (I think) should be treated as object properties, not attributes.

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

Sidebar

Related Questions

Is this even possible? I have a key-pair that I already made with GPG
I have a pair of tables that have a one-to-one relationship. I have a
I have a pair of commits that should really be just one. If I
I have a pair of classes that look something like this. There's a Generator
I have a pair of static fields with a complicated one-time initialization. I want
I have a situation where I want to map a pair of objects to
I have a pair of Rails helpers, one of which is meant to accept
Working with the MVVM pattern, I have a pair of view model classes that
I have a pair of Django models with a foreign key, one of which
I have a pair of views in my application that both display the same

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.