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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:39:32+00:00 2026-05-15T18:39:32+00:00

I have a page that selects all the elements in a form and serializes

  • 0

I have a page that selects all the elements in a form and serializes them like this:

var filter = 'form :not([name^=ww],[id$=IDF] *,.tools *)';
var serialized = $(filter).serialize();

This works, unless the form gets around 600+ elements. Then the user gets s javascript error saying that the script is running slow and may make their browsers unresponsive. It then gives them the option to stop running the script.

I have tried running the filters separately, I have tried using .not on the selectors, then serializing them, but I run into one of two problems. Either it runs faster without the error, but also does not filter the elements, or it does filter the elements and gives me the slow script error.

Any ideas?

  • 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-15T18:39:33+00:00Added an answer on May 15, 2026 at 6:39 pm

    With 600+ elements this is going to be dead slow. You need to offer Sizzle (jQuery’s selector engine) some opportunities for optimisation.

    First, consider the fact that jQuery can use the natively-supported querySelectorAll method (in modern browsers) if your selector complies with the CSS3 spec (or at least to the extent of what’s currently supported in browsers).

    With your case, that would mean passing only one simple selector to :not instead of 3 (1 simple, 2 complex).

    form :not([name^=ww])
    

    That would be quite fast… although you’re not being kind to browsers that don’t support querySelectorAll.

    Look at your selector and think about how much Sizzle has to do with each element. First it needs to get ALL elements within the page (you’re not pre-qualifying the :not selector with a tag/class/id). Then, on each element it does the following:

    (assume that it exits if a result of a check is false)

    1. Check that the parent has an ancestor with the nodeName.toLowerCase() of form.
    2. Check that it does not have a name attribute starting with ww (basic indexOf operation).
    3. Check that it does not have an ancestor with an id attribute ending in IDF. (expensive operation)
    4. Check that it does not have an ancestor with a class attribute containing tools.

    The last two operations are slow.

    It may be best to manually construct a filter function, like so:

    var jq = $([1]);
    $('form :input').filter(function(){
    
        // Re-order conditions so that
        // most likely to fail is at the top!
    
        jq[0] = this; // faster than constructing a new jQ obj
    
        return (
    
            !jq.closest('[id$=IDF]')[0]
                // this can be improved. Maybe pre-qualify
                // attribute selector with a tag name
    
            && !jq.closest('.tools')[0]
    
            && this.name.indexOf('ww') !== 0
    
        );
    
    });
    

    Note: that function is untested. Hopefully you get the idea…

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

Sidebar

Related Questions

We have a page that ordinarily has two elements arranged side-by-side. Despite exploring a
So on a specific page I have some number of form elements, anywhere between
I have a page that is generated which inserts an HTML comment near the
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when
I have a page that has an iframe From one of the pages within
I have a page that is hitting a webservice every 5 seconds to update
I have a page that is supposed to launch the Print Preview page onload.
I have a Page that has a single instance of a UserControl that itself
I have a page that contains a user control that is just a personalized
I have a page that renders slowly. The trip across the net is quick.

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.