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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:52:15+00:00 2026-06-07T11:52:15+00:00

I am adding a span elements dynamically from input field into a div. When

  • 0

I am adding a span elements dynamically from input field into a div. When they reached the right end of the div. It overflows in the same line.

However, when the number of span elements are pre-defined into a div element then they are not overflowed and they comes down and starts from a new line. I want this way.

I analysed both the element structure in firebug and both look same.

Here the fiddle for demonstration – FIDDLE

Please let me know for any mistake I am doing and if there is any workaround.

  • 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-07T11:52:17+00:00Added an answer on June 7, 2026 at 11:52 am

    Since span is an inline element, it’s affected by whitespace in the HTML.

    In your predefined example, you have a line break between each span.

    To make your JavaScript version work, you need to add some whitespace.

    Add either a line break:

    $("#box1").append("<span>"+val+"</span>\r\n");
    

    or just a space:

    $("#box1").append("<span>"+val+"</span> ");
    

    The choices are equivalent, but your intention may be clearer with a line break.

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

Sidebar

Related Questions

I am adding new span elements to a div element (using .append) of fixed
What I'm doing is adding a class to all elements who have the same
I have several same HTML elements going one after another: <span>1</span> <span>2</span> <span>3</span> I'm
This is the same question as this: https://stackoverflow.com/questions/2890620/jquery-running-a-function-in-a-context-and-adding-to-a-variable But that question was poorly posed.
Suppose I have the following HTML: <div class=container> <span class=remove>remove</span> </div> and jquery: $(.container).delegate(.remove,
I have this following where I would like to dynamically add the list elements
I have been adding new elements via jQuery in some of my projects, and
I have two elements that I would like to select <input id=iMe /> and
I'm trying to add elements into an Associative Array, which is colors = []
Bottom line: I'd like to disable (with jQuery) certain elements from being able to

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.