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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:43:55+00:00 2026-05-26T10:43:55+00:00

Browsing through the source of 1.7rc1, line 6625, I’ve found the .swap function: //

  • 0

Browsing through the source of 1.7rc1, line 6625, I’ve found the .swap function:

// A method for quickly swapping in/out CSS properties to get correct calculations
swap: function( elem, options, callback ) {
    var old = {};

    // Remember the old values, and insert the new ones
    for ( var name in options ) {
        old[ name ] = elem.style[ name ];
        elem.style[ name ] = options[ name ];
    }

    callback.call( elem );

    // Revert the old values
    for ( name in options ) {
        elem.style[ name ] = old[ name ];
    }
}

I’ve never seen it used before. Do people actually use it? For what?

  • 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-26T10:43:55+00:00Added an answer on May 26, 2026 at 10:43 am

    .swap(elem, options, callback) is a function that temporarily sets a number of CSS values (those passed in object of the 2nd argument), calls the callback (the 3rd argument) and then restores the original CSS values after the callback returns.

    jQuery uses it for temporarily changing the layout of things in order to do some measurements. For example, if you take a div object and set it to position: absolute, you will be able to get it’s true width, but if it’s in the normal layout of the document, a div takes the width of it’s container. If you step through a jQuery call to .width() or look at how that function is implemented in the source, you will see it being used.

    I’m sure you could invent/find something else to use it for, but I’ve not found a need for it other than the measurement types of use that jQuery is using it for.

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

Sidebar

Related Questions

Browsing through the source code of Microsoft's sample StockTrader application, I found this snippet
I've been browsing through all of the CSS related cross-browser questions trying to troubleshoot
Browsing through Guava libraries I saw this weird signature on the readLines method of
Browsing through the channel 9 msdn videos I found the following unanswered comment and
I was just browsing through the draft of the C++11 standard and found the
Browsing through the 2.0-wip branch of Twitter Bootstrap, I found LESS have a nice
I'm browsing through some code and I found a few ternary operators in it.
I was browsing through the code of Vosao CMS , an open source CMS
I was browsing through a webpage which had some c FAQ's, I found this
While browsing through the source code of the java.util.concurrency package, I noticed an idiomatic

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.