Abe Miessler
Abe Miessler

Reputation: 85056

Possible to use += with the css top and bottom properties in jquery?

Basically I would like to do something like this:

$("#whatever").css("bottom", "-=40");
$("#whatever").css("top", "+=40");

I saw an example on jQuery's website where they did this with the width, but when I tried it with bottom and top it didn't work.

http://jsfiddle.net/TUyLs/

Can this be done with jQuery?

Upvotes: 2

Views: 80

Answers (3)

gen_Eric
gen_Eric

Reputation: 227270

It works fine in jQuery 1.6.2. Your jsFiddle was incorrect.

You selected MooTools, not jQuery. Also, #down was not an element.

Corrected fiddle: http://jsfiddle.net/TUyLs/11/

Upvotes: 0

Jacek Kaniuk
Jacek Kaniuk

Reputation: 5229

it works, you had some other errors and you were using MooTools

http://jsfiddle.net/TUyLs/10/

Upvotes: 0

js-coder
js-coder

Reputation: 8346

Try this: http://jsfiddle.net/TUyLs/3

Yes, it work's. Make sure to insert jQuery (you inserted mootools). Also the element needs to be positioned absolute, in ordner to use top and left. Without declaring it as absolute, it'll be static, which means you won't be able to position it static.

// BTW, just a tip: You don't need to use document.ready on jsfiddle in your example. JSfiddle is inserting that automatically. (Under 'use framework': 'onLoad')

Upvotes: 4

Related Questions