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

  • Home
  • SEARCH
  • 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 7970309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:22:43+00:00 2026-06-04T07:22:43+00:00

in jquery 1.4.1 source,this css function is: css: function( elem, name, force, extra )

  • 0

in jquery 1.4.1 source,this css function is:

css: function( elem, name, force, extra ) {
        /// <summary>
        ///     This method is internal only.
        /// </summary>
        /// <private />

        if ( name === "width" || name === "height" ) {
            var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight;

            function getWH() {
                val = name === "width" ? elem.offsetWidth : elem.offsetHeight;

                if ( extra === "border" ) {
                    return;
                }

                jQuery.each( which, function() {
                    if ( !extra ) {
                        val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
                    }

                    if ( extra === "margin" ) {
                        val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
                    } else {
                        val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
                    }
                });
            }

            if ( elem.offsetWidth !== 0 ) {
                getWH();
            } else {
                jQuery.swap( elem, props, getWH );
            }

            return Math.max(0, Math.round(val));
        }

        return jQuery.curCSS( elem, name, force );
    },

    curCSS: function( elem, name, force ) {
        /// <summary>
        ///     This method is internal only.
        /// </summary>
        /// <private />

        var ret, style = elem.style, filter;

        // IE uses filters for opacity
        if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) {
            ret = ropacity.test(elem.currentStyle.filter || "") ?
                (parseFloat(RegExp.$1) / 100) + "" :
                "";

            return ret === "" ?
                "1" :
                ret;
        }

        // Make sure we're using the right name for getting the float value
        if ( rfloat.test( name ) ) {
            name = styleFloat;
        }

        if ( !force && style && style[ name ] ) {
            ret = style[ name ];

        } else if ( getComputedStyle ) {

            // Only "float" is needed here
            if ( rfloat.test( name ) ) {
                name = "float";
            }

            name = name.replace( rupper, "-$1" ).toLowerCase();

            var defaultView = elem.ownerDocument.defaultView;

            if ( !defaultView ) {
                return null;
            }

            var computedStyle = defaultView.getComputedStyle( elem, null );

            if ( computedStyle ) {
                ret = computedStyle.getPropertyValue( name );
            }

            // We should always get a number back from opacity
            if ( name === "opacity" && ret === "" ) {
                ret = "1";
            }

        } else if ( elem.currentStyle ) {
            var camelCase = name.replace(rdashAlpha, fcamelCase);

            ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];

            // From the awesome hack by Dean Edwards
            // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291

            // If we're not dealing with a regular pixel number
            // but a number that has a weird ending, we need to convert it to pixels
            if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
                // Remember the original values
                var left = style.left, rsLeft = elem.runtimeStyle.left;

                // Put in the new values to get a computed value out
                elem.runtimeStyle.left = elem.currentStyle.left;
                style.left = camelCase === "fontSize" ? "1em" : (ret || 0);
                ret = style.pixelLeft + "px";

                // Revert the changed values
                style.left = left;
                elem.runtimeStyle.left = rsLeft;
            }
        }

        return ret;
    }

but it can not use alone,who can give me a standalone code of the css 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-04T07:22:44+00:00Added an answer on June 4, 2026 at 7:22 am

    No, jQuery is very complex so you don’t can just get one method out of the source and use it.

    You can write a simple CSS function like:

    var css = function(element, property, value) {
        element.style += '; ' + property + ':' + value;
    };
    

    Or make it with hashes:

    var css = function(element, property, value) {
        if (typeof property == 'object' && value === undefined) {
            // handle css(elem, { prop : value });
            var styles = '';
            for (i in property) {
                styles += '; ' + i + ':' + property[i];
            }
            element.style += styles;
        }
        else {
            // handle css(elem, prop, value);
            element.style += '; ' + property + ':' + value;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this snazy plugin: http://remysharp.com/2007/12/28/jquery-tag-suggestion/ ** it's real small Source: http://remysharp.com/downloads/tag.js
I have a jquery function that is called on $(document).ready that modifies the css
I am running the following javascript: $('img').each( function(){ var w = parseInt(this.width); alert(w); alert(this.src);
I'm trying to follow along the demo source code for the Draggable jQuery method,
So I have this jquery: $(function() { var availableTags = [ ActionScript, AppleScript, Asp,
I'm having trouble getting jQuery's $(this) function to work as expected... or rather, to
This is about the (mootools-like) kwicks Jquery plugin: http://www.jeremymartin.name/projects.php?project=kwicks I have the same problem
If we look at the latest jQuery source at http://code.jquery.com/jquery-latest.js we see the following:
jquery.js source code is not being recognised by browser using my page.html served by
Why does JQuery ( latest source ) tie there Ajax Request Object to a

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.