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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:09:03+00:00 2026-05-15T01:09:03+00:00

I am creating an li element dynamically like this: $(data).find(‘slide’).each(function(numSlide){ var slideLink = $(this).attr(‘link’);

  • 0

I am creating an li element dynamically like this:

$(data).find('slide').each(function(numSlide){
  var slideLink = $(this).attr('link');
  var slideimage = $(this).children('slideimage').text();
  var slidedesc = $(this).children('slidedesc').text();

  $('.slider ul').append('<li><a href="'+slideLink+'"><img src="'+root+"images/top-slider-image/"+slideimage+'" alt="welcome to Burger Davis Blog" /></a><div class="note">'+slidedesc+'</div></li>');
})

But I’d like to calculate the width of the li, and I need to apply some style to it — how can I do that? If I add styles via the css method, it does not work for dynamically created elements…

Please help me to get dynamic elements’ width and how to apply styles into that?

I know we can use the live function, but I can’t get even by that..

  • 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-15T01:09:03+00:00Added an answer on May 15, 2026 at 1:09 am
    $(data).find('slide').each(function(numSlide){
      var slideLink = $(this).attr('link');
      var slideimage = $(this).children('slideimage').text();
      var slidedesc = $(this).children('slidedesc').text();
      var li = $('<li><a href="'+slideLink+'"><img src="'+root+"images/top-slider-image/"+slideimage+'" alt="welcome to Burger Davis Blog" /></a><div class="note">'+slidedesc+'</div></li>');
      $('.slider ul').append(li);
      var w = li.outerWidth();
      li.css('width', w + 100);
    })
    

    This is a contrived sample. create the link outside the append so you can access it directly and utilize either innerWidth() or outerWidth() to get the width value. Then just reference the css function of the item you create. In this example I just take the current width and add 100 to it.

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

Sidebar

Related Questions

After dynamically creating an element with this: $('#btnAddBanner').click(function () { var uid = new
I'm creating a bunch of li elements dynamically $.each(data.attributes.listingImages, function (i, obj){ if(i ==
I'm creating some HTML elements dynamically via JavaScript. Something line this: var author =
I am creating a few DOM elements dynamically like, var anchorElement = jQuery('<a />',{text:property.text});
I am creating a form using Cake.In the form there is a $this->Form->button($i); element.
I am creating my content dynamically, When a anchor tag is clicked navigate() function
I am dynamically creating the options for a select element using jQuery. Is it
I want to dynamically create a div element with id=xyz . Now before creating
This is a goofy question, so sorry about that. I'm creating html elements dynamically
I'm working on a page on which I'm dynamically creating a Facebook Like button

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.