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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:00:51+00:00 2026-06-07T14:00:51+00:00

I am trying to write a jQuery function which searches for all divs on

  • 0

I am trying to write a jQuery function which searches for all divs on the current page which have the class “rounded-corners” and then replaces those divs with a wrapping-table which contains some pretty background images. See below…

$(document).ready(function ()
{
    // For all "rounded-corners" div's on the page...
    $("DIV.rounded-corners").each(function ()
    {
        // Copy the contents of the div into a wrapping table.
        var $roundedCornersContainer = $('<table cellpadding="0" cellspacing="0" class="rounded-corners-container"> \
                                            <tr> \
                                                <td class="corner-topleft"></td> \
                                                <td class="corner-topright"></td> \
                                            </tr> \
                                            <tr> \
                                                <td class="original-content" colspan="2">THIS IS WHERE THE CONTENT IS INSERTED</td> \
                                            </tr> \
                                            <tr> \
                                                <td class="corner-bottomleft"></td> \
                                                <td class="corner-bottomright"></td> \
                                            </tr> \
                                        </table>');

        $roundedCornersContainer.find("TD.original-content").append($(this).html());

        // Replace the original "rounded-corners" div with the populated wrapping table.
        $(this).replaceWith($roundedCornersContainer);
    });
});

This works great so long as there aren’t any nested “rounded-corners” divs. If there are, then only the outermost div gets replaced with my wrapping table.

Interestingly enough, when I step through this code with a degugger, ALL of the nested divs are actually retrieved and processed — they simpy aren’t updated on screen. (NB: the outermost div is processed first, then each of the nested children).

  • Could it be that the DOM elements in the each() function are becoming stale?
  • Do I need to explicitly update the DOM somehow at the end of each iteration?
  • Or is there a way I can process all divs at once (i.e. not use the each() function)?
  • 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-07T14:00:56+00:00Added an answer on June 7, 2026 at 2:00 pm

    try this or see in jsfiddle

    $(document).ready(function ()
    {
        // For all "rounded-corners" div's on the page...
        var str = '<table cellpadding="0" cellspacing="0" class="rounded-corners-container"> \
            <tr> \
                <td class="corner-topleft"></td> \
                <td class="corner-topright"></td> \
            </tr> \
            <tr> \
                <td class="original-content" colspan="2">THIS IS WHERE THE CONTENT IS INSERTED</td> \
            </tr> \
            <tr> \
                <td class="corner-bottomleft"></td> \
                <td class="corner-bottomright"></td> \
            </tr> \
        </table>'; 
        $("DIV.rounded-corners").each(function ()
        {
    
            var tmp = $(this);
            var $roundedCornersContainer = $(str);        
            $roundedCornersContainer.insertAfter(tmp).find("TD.original-content").append(tmp);
    
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a bit of jquery which finds all h2 tags inside
I'm trying to write a function in jQuery that will add a class to
I'm trying to write a jQuery function to change out href of a link,
I am trying to write, what I thought was, a simple jQuery function to
Trying to figure out how to write a jquery formula that will sum all
I am trying to write a simple piece of Jquery in which the script
I'm trying to write a jQuery function that changes the subtotal when a radio
I am trying to write a jQuery snippet, in which I can add input
I am trying to write a jquery function but am brand new to jquery.
I'm trying to write a function in Javascript (with jQuery, if you want): function

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.