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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:18:23+00:00 2026-05-26T11:18:23+00:00

I have appended new elements in an empty ul but when I try to

  • 0

I have appended new elements in an empty “ul” but when I try to access newly appended element from jQuery but its undefined. I am designer so don’t get what’s going on. I created a simpler version at: jsfiddle.

  1. I am pulling data from another div and put into list items and final add append it to ul.thumbs —- This works great and I can see every thing inside the target ul.
  2. I tried to get li:first-child a’s class name from ul.thumbs but did not succeed. It says its undefined … while I can see it inside the ul.thumbs.

    $(document).ready(function () {
    var catName;
    var thumbLi="";
    
    $("#cat-nav li a").each(function(){        
        catName = $(this).html();
    
        $("#portdata li").each(function () {
            itemCat =  $(this).attr("class");
    
            if(catName==itemCat){
                itemCat = $(".thumb", this).html();
                    thumbLi += "<li>" + itemCat + "</li>";
            }
        });
        $(thumbLi).appendTo("div.box2 ul.thumbs");        
    });
    
    var firstOne = $(".thumbs li:first-child a").attr("class");
    alert(firstOne);/*Why is it undefined*/
    

    });

  • 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-26T11:18:24+00:00Added an answer on May 26, 2026 at 11:18 am

    var firstOne = $(".thumbs li:first-child a").attr("class");

    You are setting the class attribute of the selector into firstOne, and that selector has no class attached to it.

    this fiddle works and will alert the class of the A tag of the first li inside .thumbs

    Perhaps you meant to alert the element itself and not its class?

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

Sidebar

Related Questions

I am dynamically appending form elements. The newly appended elements need to have distinct
I'm having trouble when opening a simple HttpConnection from the simulator, I've have appended
Do assignments in document.ready ( click(fn) specifically) apply to newly appended elements that match
I have below is the html code for TD which gets appended after matching
I have a jquery block that does some ajax stuff like this: $.ajax({ url:
I need to call a Javascript function from an a element.. something like this:
I have an input field that is appended to the HTML in a div.
I'm pretty new to Python and am completely confused by .join() which I have
I have a vector that I am loading with a know amount of elements
I'm trying to build a tree of LI/UL elements from an interal object I

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.