Hi guys, I have come across something really confusing, so I wonder if somebody can help me with that.
I wanted to increment the width of a container using this version of the .css()
method:$( "div.example" ).css( "width", function( index )
as per http://api.jquery.com/css/#css-propertyName-functionindex--value
So here is my html:
<div class="myDiv"> </div>
and my css for that container
.myDiv {
background: url("overlayArrow_03.png") no-repeat scroll -20px 0 rgba(0, 0, 0, 0);
border: 1px solid #0000FF;
height: 150px;
left: 35px;
position: absolute;
top: 217px;
width: 300px;
}
OK. So this version of a jquery script does the trick:
$(".myDiv").css("width", function(index){
return index + 120;
});
although the final width of the container is now 120px and not 420 as expected. I take that's because the value of index is 0, so it would make sense.
On the jquery site, they also say that the version of the above funcion should be instead
$( "div.example" ).css( "width", function( index, value )
that applied to my case is
$( "div.example" ).css( "width", function( index, value )
return value + 120;
});
but alas, it doesn't work. It doesn't cause an error and the width of the container remains 300px.
Any idea please?
thanks