css:
#obj { display:block; width:10%; height:30px; background-color:#006600; }
javascript:
$(document).ready(function() {
$('#obj').css('width','+=10');
});
html:
<span id="obj"></span>
it won't grow.
css:
#obj { display:block; width:10%; height:30px; background-color:#006600; }
javascript:
$(document).ready(function() {
$('#obj').css('width','+=10');
});
html:
<span id="obj"></span>
it won't grow.
$(document).ready(function() {
$('#obj').width($('#obj').width()+10)
});
--------Edit---------------
I just checked jQuery resources: your code is correct too , but for that you need jQuery version 1.6+
try this http://jsfiddle.net/nvmwu/2/ with different versions of jQuery
-----------Extract from Jquery Api--------
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.
$(function() {
$('#obj').css('width', function () {
return $(this).width() + 10;
});
});
Works for me in FF5, but only as of jQuery 1.6, and your comments elsewhere indicate that you are using jQuery 1.5.2.
In fact, the documentation even says this:
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.
Please read it next time.
I had this problem using jQuery 1.6.1. Updated to 1.7.1 and it works.
Looks like this was fixed in 1.6.2. From the release notes:
".css() doesn’t work with relative values on hyphenated properties"
http://bugs.jquery.com/ticket/9237
http://blog.jquery.com/2011/06/30/jquery-162-released/