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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:57:12+00:00 2026-06-09T22:57:12+00:00

See http://jsfiddle.net/PAWAS/3/ JavaScript: $(document).ready(function () { $.each($(.item), function(index, value) { thisEl = $(this); thisEl.children(strong).after(<span

  • 0

See http://jsfiddle.net/PAWAS/3/

JavaScript:

$(document).ready(function () {

    $.each($(".item"), function(index, value) { 
        thisEl = $(this);
        thisEl.children("strong").after("<span style='display:inline-block'>");
        $("</span>").appendTo(thisEl);

    });
});​

HTML:

<div class="item">
    <strong>Time Cond:</strong>
    MorningCheck
</div>​

Should be:

<div class="item">
    <strong>Time Cond:</strong>
   <span> MorningCheck</span>
</div>​

But the </span> gets injected before the text MorningCheck

What did I do wrong?

  • 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-09T22:57:14+00:00Added an answer on June 9, 2026 at 10:57 pm

    .append and .appendTo manipulate the DOM, the don’t create HTML strings. Have a look at a similar question and my answer here: Using .append() with lists places text on a newline.

    Assuming there is always only one (non-empty) text node inside the element, you can use the following to put it inside a span element:

    $(".item").each(function() {
        // get all child nodes, including text nodes
        $(this).contents().filter(function() {
            // is text node and does not only contain white space characters
            return this.nodeType === 3 && $.trim(this.nodeValue) !== '';
        }).wrap('<span style="display:inline-block"></span>'); // wrap in span
    });
    

    DEMO

    This looks for non-empty text nodes and wraps them inside a span element. If there are multiple text nodes, you might only want to get the .last() of them, or if you want to target the text node after the strong element in particular, you could do:

    $($(this).children('strong').get(0).nextSibling).wrap(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running this code in Firefox 11 on Windows 7. (See http://jsfiddle.net/QStkd/ ). $('<div><input
See here: http://jsfiddle.net/zYcJm/ The jQuery should be validating each field to check if they
See here for code: http://jsfiddle.net/ecFBK/10/ I'm having a hard time getting this to work
See http://jsfiddle.net/jFzhC/ for the button I'm looking for. Although, this only allows for one
I have the following fiddle for people to see http://jsfiddle.net/defaye/DhaHP/4/ The result on full
I've got a toggle menu, please see http://jsfiddle.net/Wp2em/41/ for code and functions. On the
I have a menu with tiled images w/text under them. See Fiddle: http://jsfiddle.net/techydude/GF8tS/ Is
See the fiddle: http://jsfiddle.net/stefek99/9m5NZ/1/ Get the source: http://pastie.org/3654715 Chrome 17 : just works. IE
Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
See here for my issue: http://jsfiddle.net/FvBqA/126/ My issue is that I want to be

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.