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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:45+00:00 2026-06-10T12:39:45+00:00

I am attempting to create a bunch of list items dynamically, the structure I

  • 0

I am attempting to create a bunch of list items dynamically, the structure I am looking for is

<li>
    <a href="Pending.aspx">
        <img src="images/gf.png" alt="" class="ui-li-icon">My Stuff
        <span class="ui-li-count">4</span> 
    </a>
</li>

I am attempting to create this structure with this code but it seems to be breaking when I add the "img" portion to it. If I take the img portion out it at least works but no quite what I am looking for. Any ideas on how to fix this?

 $('ul').append(
        $('<li>').append(
        $('<a>').attr('href', 'some link').attr('data-container', 'listview').append(
        //THIS BREAKS IT
        $('<img>').attr('src','some image').attr('alt','').append(
        $('<span>').attr('class', 'tab').append('1')
        ))));

I am trying to dynamically create the list items found here:
http://jquerymobile.com/demos/1.1.1/docs/lists/lists-icons.html

Notice they have image tags that are NOT closed. That is how its valid to add the span tag I guess. Not sure how I can accomplish NOT closing the img tag in javascript?

  • 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-10T12:39:46+00:00Added an answer on June 10, 2026 at 12:39 pm

    Yes, and it should: an img is a void element, it cannot have children, child-nodes or descendants of any kind.

    To achieve what you seem to want (from reading your code), I’d suggest:

    var list = $('<ul />').appendTo('body'),
        listElem = $('<li />').appendTo(list),
        link = $('<a />', {
            'href': 'pending.aspx',
            'class' : 'ui-li-icon'
        }).attr('data-container', 'listview').text('My Stuff').appendTo(listElem);
    $('<img />', {
        'src': 'images/gf.png',
        'alt': 'alttext'
    }).prependTo(link);
    $('<span />', {
        'class': 'ui-li-count'
    }).text('4').appendTo(link);​
    

    JS Fiddle demo.

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

Sidebar

Related Questions

Im attempting to create a simple list out of some elements I stole from
I'm attempting to create thumbnails out of some images, each of which isn't necessarily
I am attempting to create a custom tableview where I have a list of
I'm attempting to create a SelectList by wrapping a whole bunch of model entities
While attempting to create a replacement tablespace for USER, I accidentally created a datafile
Im attempting to create a new operator :? on lists, which operates the same
I attempting to create an 800x500 div with four overlapping divs inside the container
I attempting to create custom tabs using this . But when I try to
I'm attempting to create a table for monitoring purposes using the following script: $w3wppriv
I am attempting to create a report, utilizing a matrix, that only displays columns

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.