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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:46:11+00:00 2026-06-07T23:46:11+00:00

I have some kind of webapp here, which of course incorporates JavaScript and jQuery.

  • 0

I have some kind of webapp here, which of course incorporates JavaScript and jQuery.
On load, a functions wraps a span around every letter of a text – about 150 letters. Then the user can select the letters and after a confirmation, a result is displayed. Everything works nice and smooth, only the last part really kills the performance.

The results are saved in three arrays. After on click the functions fires which adds classes to the clicked elements (this is the confirmation).

I do it like this (3 times, for each array):

$.each(myArr, function( i, v ){
    $(v).addClass( "my-class" );
});

It works this way, but because I manipulate the DOM heavily it kills the performance.

I am on a MacBook with 2.26 GHz and 2 GB RAM and I am not able to run a simple tooltip or anything after the classes has been added. Especially if one array is really full this has a negative performance impact.

I already tried to optimize the script. I cached every DOM object that is used more then once, but this is not possible in every case (I think…). I also used selectors like .my-class and #my-id instead of span[class = my-class] and span[id = my-id] to speed up everything. Only the last array part is bad.

Is there any way to optimize this $.each part? Caching or somehting? Or maybe using another technique?

I don’t expect the script to be SUPER fast – but adding a simple tooltip after the results are shown should be possible.

  • 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-07T23:46:13+00:00Added an answer on June 7, 2026 at 11:46 pm

    What seems to be the problem is that you cause a lot of browser reflows. This happens every time you make certain changes to an object in the DOM (like changing its size, removing/appending it etc). To prevent this from happening you can:

    • Remove all objects at once by removing the parent object containing all objects (this causes one reflow).
    • Make all the neccessary changes while the objects aren’t part of the DOM.
    • Put the parent object back in the DOM (which once again causes a reflow).

    If removing the parent object causes visual distractions you can instead deep clone it (var clone = parent.cloneNode(true)), make all the changes to the clone and then replace the parent object (parent.parentNode.replaceChild(clone, parent)). Be aware if the objects have any javascript event listeners you need to rebind these to the cloned objects.

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

Sidebar

Related Questions

Here's a problem. Developers have some kind of a task (develop certain feature), which
I have some kind of problem with jQuery selectors. Let's say i want to
I come back here because I have some kind of problem. (I posted 2
I want to have some kind of single list that is initialized in a
I'm wondering if NFC chips have some kind of unique identifier? I have Mifare
In my rails model I have some kind of template system. I want to
I have a question about reflection I am trying to have some kind of
Horrible title, I know. I want to have some kind of wordwrap, but obviously
I've figured I have to do some kind of API where the Android app
I have a need for some kind of information that is in essence static.

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.