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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:24:14+00:00 2026-05-27T17:24:14+00:00

I have the following HTML code on my page. There is no containing element,

  • 0

I have the following HTML code on my page. There is no containing element, it’s just in the body.

<b>SqFt per Carton: </b>24.30<br>

Using script, I want to wrap 24.30 in a span tag with a class so the result will look like this:

<b>SqFt per Carton: </b><span class="sqft_cart">24.30</span><br>

How can I do this?

  • 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-27T17:24:14+00:00Added an answer on May 27, 2026 at 5:24 pm

    Since you don’t have a containing element you can use .nextSibling() to get the text node for 24.30. Then .insertAdjacentHTML() inserts the new span after deleting the old text node. Since I don’t know what the rest of your page looks like, I’ll assume there could be multiple <b> elements, but the code will work either way.

    Demo: http://jsfiddle.net/ThinkingStiff/6ArzV/

    Script:

    var bs = document.getElementsByTagName( 'b' );
    
    for( var index = 0; index < bs.length; index++ ) {
    
        if( bs[index].innerHTML.indexOf( 'SqFt per Carton:' ) > -1 ) {
            var text = bs[index].nextSibling,
                span = '<span class="sqft_cart">' + text.nodeValue + '</span>';
            text.parentNode.removeChild( text );
            bs[index].insertAdjacentHTML('afterEnd', span);
        };
    
    };
    

    HTML:

    <b>SqFt per Carton: </b>24.30<br>
    <b>Price per Carton: </b>193.00<br>
    <b>SqFt per Carton: </b>12.90<br>
    <b>Price per Carton: </b>147.00<br>
    <b>SqFt per Carton: </b>14<br>
    

    CSS:

    .sqft_cart {
        color: red;
    }
    

    Output:

    enter image description here

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

Sidebar

Related Questions

Assuming I have the following ASP.NET HTML Code: <html> <head><title>Test Page</title></head> <body id=bodyID> <asp:Label
I have the following HTML Code <%@ Page Language=C# %> <html> <head> <title></title> </head>
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have the following html code. <html> <body> <div style=max-width:1600px; min-width:900px; > <table> </table>
I have the following html code: <mytag> Just Some Text </mytag> And I have
Just a (hopefully) quick question, I have the following HTML code: <tr> <td><img src=img/icons/file_pdf.png></td>
I have the following HTML containing a drop down list (single selection) <script type="text/javascript">
I have the following block of HTML code more than once <div id=page_1 class=page>
I have the following HTML page: sample_page.html: <h1>sample html page</h1> <script type=text/javascript src=sample_page.js/> The
To those jQuery experts out there. I have the following markup and code: <html>

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.