jQuery API

.css()

Contents:

.css( propertyName ) Returns: String

Description: Get the value of a style property for the first element in the set of matched elements.

  • version added: 1.0.css( propertyName )

    propertyNameA CSS property.

The .css() method is a convenient way to get a style property from the first matched element, especially in light of the different ways browsers access most of those properties (the getComputedStyle() method in standards-based browsers versus the currentStyle and runtimeStyle properties in Internet Explorer) and the different terms browsers use for certain properties. For example, Internet Explorer's DOM implementation refers to the float property as styleFloat, while W3C standards-compliant browsers refer to it as cssFloat. The .css() method accounts for such differences, producing the same result no matter which term we use. For example, an element that is floated left will return the string left for each of the following three lines:

  1. $('div.left').css('float');
  2. $('div.left').css('cssFloat');
  3. $('div.left').css('styleFloat');

Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both .css('background-color') and .css('backgroundColor'). Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255).

Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.

Example:

To access the background color of a clicked div.

<!DOCTYPE html>
<html>
<head>
  <style>
div { width:60px; height:60px; margin:5px; float:left; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<span id="result">&nbsp;</span>
<div style="background-color:blue;"></div>
<div style="background-color:rgb(15,99,30);"></div>

<div style="background-color:#123456;"></div>
<div style="background-color:#f11;"></div>
<script>
$("div").click(function () {
  var color = $(this).css("background-color");
  $("#result").html("That div is <span style='color:" +
                     color + ";'>" + color + "</span>.");
});

</script>

</body>
</html>

Demo:

.css( propertyName, value ) Returns: jQuery

Description: Set one or more CSS properties for the set of matched elements.

  • version added: 1.0.css( propertyName, value )

    propertyNameA CSS property name.

    valueA value to set for the property.

  • version added: 1.4.css( propertyName, function(index, value) )

    propertyNameA CSS property name.

    function(index, value)A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old value as arguments.

  • version added: 1.0.css( map )

    mapA map of property-value pairs to set.

As with the .prop() method, the .css() method makes setting properties of elements quick and easy. This method can take either a property name and value as separate parameters, or a single map of key-value pairs (JavaScript object notation).

Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both .css({'background-color': '#ffe', 'border-left': '5px solid #ccc'}) and .css({backgroundColor: '#ffe', borderLeft: '5px solid #ccc'}). Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.

When using .css() as a setter, jQuery modifies the element's style property. For example, $('#mydiv').css('color', 'green') is equivalent to document.getElementById('mydiv').style.color = 'green'. Setting the value of a style property to an empty string — e.g. $('#mydiv').css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or <style> element.

As of jQuery 1.6, .css() accepts relative values similar to .animate(). Relative values are a string starting with += or -= to increment or decrement the current value. For example, if an element's padding-left was 10px, .css( "padding-left", "+=15" ) would result in a total padding-left of 25px.

As of jQuery 1.4, .css() allows us to pass a function as the property value:

$('div.example').css('width', function(index) {
  return index * 50;
});

This example sets the widths of the matched elements to incrementally larger values.

Note: If nothing is returned in the setter function (ie. function(index, style){}), or if undefined is returned, the current value is not changed. This is useful for selectively setting values only when certain criteria are met.

Examples:

Example: To change the color of any paragraph to red on mouseover event.

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:blue; width:200px; font-size:14px; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
  <p>Just roll the mouse over me.</p>

  <p>Or me to see a color change.</p>
  
<script>
  $("p").mouseover(function () {
    $(this).css("color","red");
  });
</script>

</body>
</html>

Demo:

Example: Increase the width of #box by 200 pixels

<!DOCTYPE html>
<html>
<head>
  <style>
  #box { background: black; color: snow; width:100px; padding:10px; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
  <div id="box">Click me to grow</div>
  
<script>
  $("#box").one( "click", function () {
    $( this ).css( "width","+=200" );
  });
</script>

</body>
</html>

Demo:

Example: To highlight a clicked word in the paragraph.

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:blue; font-weight:bold; cursor:pointer; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<p>
  Once upon a time there was a man
  who lived in a pizza parlor. This
  man just loved pizza and ate it all 
  the time.  He went on to be the
  happiest man in the world.  The end.
</p>
<script>
  var words = $("p:first").text().split(" ");
  var text = words.join("</span> <span>");
  $("p:first").html("<span>" + text + "</span>");
  $("span").click(function () {
    $(this).css("background-color","yellow");
  });

</script>

</body>
</html>

Demo:

Example: To set the color of all paragraphs to red and background to blue:

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:green; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
  <p>Move the mouse over a paragraph.</p>
  <p>Like this one or the one above.</p>

<script>
  $("p").hover(function () {
    $(this).css({'background-color' : 'yellow', 'font-weight' : 'bolder'});
  }, function () {
    var cssObj = {
      'background-color' : '#ddd',
      'font-weight' : '',
      'color' : 'rgb(0,40,244)'
    }
    $(this).css(cssObj);
  });
</script>

</body>
</html>

Demo:

Example: Increase the size of a div when you click it:

<!DOCTYPE html>
<html>
<head>
  <style>
  div { width: 20px; height: 15px; background-color: #f33; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
  <div>click</div>
  <div>click</div>

<script>
  $("div").click(function() {
    $(this).css({
      width: function(index, value) {
        return parseFloat(value) * 1.2;
      }, 
      height: function(index, value) {
        return parseFloat(value) * 1.2;
      }

    });
  });
</script>

</body>
</html>

Demo:

Support and Contributions

Need help with .css() or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to .css()? Report it to the jQuery core team.

Found a problem with this documentation? Report it to the jQuery API team.

* All fields are required
  • http://twitter.com/mrtypo Etienne Dupuis

    If you have a background image, and want to use a rollover, i made the following: Name your background images with blablabla-off.png or blablabla-on.png. Then you only set the class “box” to the items you want the rollover to happen

    $(“.box”).mouseenter(function() {

    $(this)
    .css({ background: $(this).css(“background-image”).replace(“-off.”, “-on.”) + 'no-repeat' });
    });

    $(“.box”).mouseleave(function() {
    $(this)
    .css({ background: $(this).css(“background-image”).replace(“-on.”, “-off.”) + 'no-repeat' });
    });

  • Ben Hollis

    I wouldn’t recommend that – why not just change the background image in CSS by adding and removing a class? Or use :hover in your CSS and avoid JS altogether.

  • Jonathan

    If you really need to use jQuery to achieve that effect, jQuery's .hover() method is simpler.

    $(“.box”).hover(function(){
    //code for mouseover goes here
    },
    function(){
    //code for mouseleave goes here
    });

    That being said, I will echo Ben Hollis in saying that .box:hover in your CSS will achieve the same effect in all major browsers except IE6 and lower without requiring the use of javascript at all.

  • http://mindstormskid.myopenid.com/ MindstormsKid

    The fact that `this` is set to the current DOM element in the setter function should be mentioned.

  • http://www.mobilgistix.com Johann Blake

    I noticed that when retrieving style values, IE will return null if the style was never set but Firefox will return an empty string “”. Is there anything in JQuery that can easily test for the absence of a value? I end up writing statements that need to check for both null and “” and this gets tedious.

  • http://www.mobilgistix.com Johann Blake

    I notice that when you attempt to set the value of an style attribute for an attribute that doesn't exist, IE will create the attribute and store the value. Firefox simply ignores the attempt to set the value on a non-existent attribute and therefore after attempting to read back from the attribute after setting it, it will always return an empty string “”.

  • http://macrolinz.com BlueCockatoo

    Also missing from this new documentation (unless it's changed in the latest version of jQuery) is the fact that if you pass in an empty string for a value to .css(property, value) it will remove the style property from the element. If that functionality has changed, please reply to this to let me know.

  • Mark

    I notice that this is case sensitive. .css(“Overflow”,”Auto”) doesn’t work but .css(“overflow”,”auto”) does.

  • Anonymous

    $(‘el’).css(‘margin-right’) returns ’0px’ if ‘margin-right’ is set to ‘auto’…… this is not correct, it should return ‘auto’ .

  • http://anentropic.wordpress.com Anentropic

    You appear to have to quote the property names if you’re using the ‘map’ form, eg:
    $el.css({‘overflow-y’: ‘hidden’})

    The last example in the docs shows:
    $(this).css({
    width: function(…

    but I get an error if it’s not quoted. (FF3.6 OSX)

  • http://www.learningjquery.com/ Karl Swedberg

    Property names only need quotation marks if those names include characters that aren't permitted (anything other than letter, number, or underscore, if memory serves me correctly). So, .css({marginRight: '10px'}) and .css({'margin-right': '10px'}) are fine, but .css({margin-right: '10px'}) is not.

  • http://www.learningjquery.com/ Karl Swedberg

    It wasn’t in the old documentation, either.

  • http://www.cnblogs.com/zhangziqiu ZQ

    in IE8 return “auto” but in FF return “0px”, I think it’s because different browsers set different default values of CSS properties.

  • http://www.learningjquery.com/ Karl Swedberg

    In which case, you should use .attr(), or better yet, .data(), rather than .css()

  • Kurt

    How would you clear/remove a css style?

  • http://twitter.com/spektrummedia Vincent Girard

    To remove the css I just set the value to null ex : $img.css(“width”, null); and it worked.

  • Anonymous

    If you want to remove a background-image css attribut, you have to do like that:
    jqObject.css(‘background-image’, url(”));

    jqObject.css(‘background-image’, ”/null); doesn’t work.

  • http://twitter.com/Grumpicus Erik

    This worked for me:

    $(“p”).css({‘background-color’:'inherit’});

  • Dale Larsen

    Leave the value empty, e.g. nothing in between the single quotes.

    Do this:
    $(“p”).css(‘background-color’,”);

    For multiple:
    Do this $(“p”).css({
    ‘background-color’:”,
    ‘border-color’:”
    });

    Or to remove the styling completely you can do:
    $(“p”).removeAttr(‘style’);

  • http://www.google.com/profiles/114319216267739098912 ChrisH619

    Be wary of value names declared in JSON syntax, without encapsulating the name as a string you'll need to change the name as some characters arent allowed.

    So any css you'd normally use, try removing the '-' and capitalising the next char.
    e.g margin-right => marginRight, background-color => backgroundColor etc

    and remember that any values that are not numbers, boolean, or null(s) need to be declared as a string in JSON (eg margin-right:3px => marginRight:'3px', background-color:#FF0000 => backgroundColor:'#FF0000')

  • Geoffrey

    I agree. This should be uniform across browsers, no?

  • Jake

    Is it possible to get the css of an element’s :hover?

  • Anonymous

    I think what we’re looking for in JS and can’t find in jQuery is the follow:
    var mysheet=document.styleSheets[0], targetrule; //get the stylesheet..assuming only 1
    var myrules=mysheet.cssRules? mysheet.cssRules: mysheet.rules;//get the all items
    for (i=0; i<myrules.length; i++){ //loop through all items looking for what you want
    if(myrules[i].selectorText.toLowerCase()==”.daymark:hover”){
    //your search criteria must include the ‘.’ or ‘#’ or whatever it may have before it
    //even if your class has upper case in it, make them lower case in the search
    //my actual class is ‘dayMark:hover’
    targetrule=myrules[i]; //assign the rule to targetrule
    break;
    }
    }
    targetrule.style.height=(matrixH-50)+”px”; //make the change the same way you would any other object

  • http://www.learningjquery.com/ Karl Swedberg

    Check out the jQuery Rule plugin:
    http://flesler.blogspot.com/2007/11/jqueryrule.html

    In the future, this type of question is better asked on the jQuery forum.

  • Hayden

    inherit won't work for the height attribute in IE7

  • Edwin

    You can also try this:
    $(eId).css(style, 'transparent');

  • Tara_irvine

    is it possible to have $('#divID').css({“left”: “+=780px”}); what i'm looking for is $('#divID').animate({“left”: “+=780px”}); but I don't want the animation…
    Really stuck :(

  • Kurt Davis

    You may need to quote the keys in that css object.
    like:
    dot.css({“width”:”400px”,”position”:”absolute”,”top”:”500px”});

  • Aleksandr-krylov

    I can not understand, I also did. I was surprised and. If I put directly in the <div id=”effectqwe” style=”width: 400px; height: 200px; padding: 0.4em; top: 30px”>, something works. And if you try to make changes through “jquery”, it does not work “position” and “top”.

  • http://www.litegame.net Bingjie2680

    you may try this: dot.css(“top”,”500px”)
    .css(“position”, “absolute”);

  • http://hkansal.myopenid.com/ HKansal

    You can save the previous “left” value first.

    var oldLeft = parseInt($(“#divID”).css('left'));
    $(“#divID”).css('left',oldLeft + 780);

    this works for sure ;)

  • http://twitter.com/kisso699 Spyros Hajisavvas

    maybe this works?
    $('#divID').css('left', function(index) {
    return index + 780 + 'px';
    });
    taken from the description

  • Askjdlsakjl

    fuck

  • Askjdlsakjl

    I'm sorry. Was my mistake. Please Please delete my posts. Please.

  • http://www.learningjquery.com/ Karl Swedberg

    Please use the jQuery forum for support requests.

  • http://www.learningjquery.com/ Karl Swedberg

    Actually, that would not do it. The index is not the same thing as the value.

    Try this instead:

    $('#divID').css('left', function(index, val) {
    return (parseFloat(val) + 780) + 'px';
    });

  • RaniA

    alert($(“”,{“class”:”myclass”}).css(“width”));
    Internet Explorer 8 gives me undefined,firefox gives me the right width;
    Also tried it with “stylewidth”, but it doesnt work. Anyone got an idea how to fix it so it can also run under IE 8 ?

  • Yo

    Try with:
    alert($(“#myclass”).css(‘width’));

  • Yo

    Sorry, I had a mistake, the correct way is:
    alert($(“.myclass”).css(‘width’));

  • Jason ‘Zeus’ Brown

    This way is a little more ideal:
    jqObject.css(‘background-image’, ‘none’);

  • http://twitter.com/flimcc flim

    What would be the best possibility to deal with border-spacing? I understand that margin isn’t supported (probably because of the same issue). element.css(‘border-spacing’) would return something like “1px 1px” (for horizontal and vertical spacing) and to my knowledge there’s no way to ask for each separate?

  • lara

    How can we change element color permanently.Suppose that I ve click red button and change all h3 headers into red and after that when I reload the page how can I remain all h3 headers red.I m not sure whether you understand my question or not.

  • http://www.kijote.com.ar Kijote

    lara, you can do it at the server side, the page would send the change and asociate it to the user session (because I suppose you can't change it for all users), then when the user stay in the web page, the page could load another user css. It is possible if the web page is written in a dynamic server language like PHP.
    So, if you want to change it for all page users, you must create a admin section in your page to do the same thing (change the global css with the changes made).

  • ashraf

    hi.
    I have a text re-size option in my web page(normal, medium and large). and i have a light box also. the problem is if i click in normal text the light box content is appearing fine but once i select large size, the right side of the paragraph text in the light box is cutting partially. this is happening in ie6 only rest of the browsers are fine. can anybody suggest a way to fix this issue.

  • http://twitter.com/RuneImp RuneImp

    alert($(“.myclass”)[0].width()); will give you the width of the first instance of “myclass” sans padding and margin.
    alert($(“.myclass”)[0].innerWidth()); will include padding and
    alert($(“.myclass”)[0].outerWidth()); will include padding and margin.

  • Bmartin

    Is there a way to remove a property? For example, the iPhone does not support the overflow:auto or scroll, so I thought I would remove the overflow property if the browser detected is safari mobile. How can I remove the property?

  • http://www.martinsmucker.com Michael Martin-Smucker

    What is returned if I try to find the value of a CSS property that hasn't been explicitly set?

    This, for example, assuming that z-index hasn't been set: $('#element').css('z-index');

    If I would try to save this value to a variable, would it just be null?

  • http://twitter.com/jbsil01 Jesse Silverstein

    As of jQuery 1.4.3, .css('property',null) no longer clears the property. In 1.4.2, and previous versions, the property was deleted as if it had never been set. Is this expected behavior for 1.4.3? If so, what is the 'correct' way to clear a css property in 1.4.3+?

  • http://twitter.com/jbsil01 Jesse Silverstein

    You can set it to an empty string (“”), which effectively removes it. This works in 1.4.2 and 1.4.3. You could set it to null in 1.4.2, but that no longer works.

  • Haskell_noob-github

    @Jesse Silverstein

    Check jQuery Ticket http://bugs.jquery.com/ticket/7233

    Actually using .css( propertyName, null ) is just wrong. The correct way is .css( propertyName, '' )

  • Collapsus

    in IE $('body').css('border') >> undefined (not '' like in FF)
    it's bug, or my mistake?

  • Young

    this code doesn't work in IE8.

    var rect = $(“#id”).css(“clip”);
    alert( rect );

    result :
    “undefined”

    but works well in both of firefox and chrome.
    I can't find out what the problem is..

  • Young

    In additionally to previous comment.
    It's was hard to get each value from the rect;
    so I got the value in this way.

    $(“#id”).css('clip', function(index, val){
    val = val.replace(/,/gi, “”);
    //alert( val );
    val = val.substr( 5, val.length-6 );
    rt = val.split(” “);
    right = parseInt(rt[1]);
    left = parseInt(rt[3]);
    left–; right++;
    return “rect(“+rt[0]+”,”+right+”px,”+rt[2]+”,”+left+”px)”;
    });

    anybody know better way?

  • Young

    var rect = $(“#id”).css('clip');

    the value of rect was diffrent in each browser.
    the value was “rect(0px, 10px, 20px, 30px)” in firefox.
    but in chrome, the value was “rect(0px 10px 20px 30px)”…
    is that normal ??

  • tom

    Hello, I have problem with getting background-color. I get “transparent” instead of a color-value while typing: var color = $(dom_element).css('background-color');

  • mild

    function(i,v){

    var a=v.replace(“rect(“,”").replace(“)”,”").split(“,”);

    return “rect(“+[a[0],parseInt(a[1])++,a[2],parseInt(a[3])–].join(“,”)+”)”

    }

  • robin

    use 'backgroundColor'

  • newtonpage

    Does not work in IE8 (I do not allow less than IE8 on the site with a server-side “sniffer”):

    var element = $(“#whatever”);
    var showOverClosed = “0px -13800px”;
    element.css({backgroundPosition: showOverClosed});

    This works in all other browsers on Mac and Win.

    IE8 breaks and the 'getter' version returns 'undefined'.

    Only this seems to work in IE (an example getter):

    bgPosY = parseInt(element.css('background-position-y'));

    This is huge problem – does jQuery css() work in IE?

  • Michael

    It wont work in Internet Explorer:

    var abc = $('#tster').css('height'); alert (abc);
    > FF returns RGB value -> thats correct
    > IE8 returns undefined -> why? how can i solve this problem?

    Is there a solution to get all css values?

  • Wes

    Try

    abc = $('#tster').height(); alert (abc);

    At least it works for me in IE8.

  • Michael

    thank you it works for me, but i wrote it in plain javascript.

  • Mariusz Stanislawczyk

    Hello, there seems to be a problem with jQuery 1.4.4 – using nyromodal plugin 1.6.2 i`m receving error in firebug: “jQuery.css is not a function”. Debugger shows 6347 line (hide function) as error line: var display = jQuery.css( this[i], “display” );
    What`s wrong with this?

  • Draco

    Your example works as advertised in IE 8.0.6001.18702.

  • Freeztyler

    Is there a way to restore the original css after a change was made with jquery?

    Example:
    Change when function 1 clicked…
    $(“.play_q_btn”).css('background-position', '-21px -98px');

    When other button is clicked I want the state of the first button to go back to original css formatting…
    $(“.play_q_btn”).css('background-position', '-21px 0px');
    $(“.play_q_btn:hover”).css('background-position', '-21px -49px');

    but I lose the hover function when I do this.

  • mansh

    how can i set an style property?

  • http://twitter.com/bl4h Joey

    When hiding or showing something on mouseover, I find it works much better when you check to see if the element is already visible or not before triggering it again. something like

    $('.blocks').mouseover(function() {
    if ($(this).find(“span”).css(“display”) == “none”) {
    $(this).find(“span”).show(“fast”);
    }});

    This helps stop elements from having a hair trigger and popping in and out unexpectedly ….

  • Elgringopedro

    I do experience a quite sticky bug over here. I'd like to get the computed style ('display') on some dom nodes containing elements with display set to 'inline-block', using the .css function, this way: $('#myID').css('display'). It does return the display style indeed, but the value returned, even for the elements whose display is set to 'inline-block' is ALWAYS 'block' !!

    I've tried doing it in pure javascript, tried every trick found in many javascript sites but still without any success.

    If somebody's got any idea, it is more than welcome.

    Cheers

  • Markus

    They're equivalent in the context. My understanding is that the default background color for pretty much all elements is transparent. So, unless one is stated explicitly, you'll always get that when asking for an element's background color.

  • Markus

    They're equivalent in the context. My understanding is that the default background color for pretty much all elements is transparent. So, unless one is stated explicitly, you'll always get that when asking for an element's background color.

  • Djabor

    Might be a bit late, but i assume you can use that code and just set the animation time to 0, so you still get the effect, just without any animations.
    There is also a global settings to turn of all animations, so you can also refer to the effects section to find that.

  • Piki

    I have little problem with version 1.4.4

    I have this HTML and jQuery code:

    <input id=”abc” name=”abc” style=”height: 14mm;” type=”text”>

    height = $('#abc').css('height');

    version 1.3.2 return => 14 (this is in mm)
    version 1.4.4 return => 53 (this is in px)

    Is it bug? I would like to get height in “mm” not in “px”.

  • Gravulator

    It will return Undefined, Null, or the default setting that CSS automatically puts (E.g. it would return transparent for the background color).

    A great way to check if it is pulling the correct value, try this.
    var z = $(“#element”).css('z-index');
    alert(z);

    Alerts is god's gift to JavaScript programmers.

  • http://www.martinsmucker.com Michael Martin-Smucker

    Thanks for the answer! In nearly all cases, though, CSS properties will

  • Lingtalfi

    Considering this code :

    $(document).ready(function(){
    $(“#clickme”).click(function(){
    $(“#myTable”).css('borderStyle','solid');
    $(“#myTable”).css('borderColor','black');
    $(“#myTable”).css('borderWidth','3px');
    });

    $(“#clickme2″).click(function(){
    alert($(“#myTable”).css('borderWidth'));
    });
    });

    When clicking on clickme2 button, I don't get the ( what I ) expected
    value of 3px.

    Does that mean that jquery's css method cannot access styles that are dynamically
    set ?

  • s_g

    I have the same question as Piki above. CSS values set in 'em' units when using version 1.4.2 worked fine but are being returned in pixel converted values in 1.4.4 when called upon.

    For example, $(“#thisEl”).css('width') returns 809px even though it is set in the stylesheet as 50.50em.

    This is a problem moving forward, as all values would require conversion throughout a very large project and associated scripting. Assuming that the latest greatest jQuery version continues to be used.

  • Daniel Mediaguise

    I thought that using $('#something').css() returned all the class names on that object. Is this true?

    If not, I think that this would be a great feature as opposed to using $('#something').attr('class') which seems rather abstract in the whole jQuery concept…

  • dpmguise

    It looks like the values are the same… is that a typo?

  • dpmguise

    Just to add to that – altering the core jQuery.fn.css like so would achieve the result I am after…

    if (name === undefined && value === undefined) {
    return this[0].className;
    } else if ( arguments.length === 2 && value === undefined ) {
    return this;
    }

  • Thomasin

    All I want is to be able to toggle the css I specify. I've searched everywhere, and adding and removing classes won't work for me.
    Is this even possible?

  • juss

    The “behavior” property doesn't seems to work