Element.setStyle() not working as expected
Reported by Julien Garand | May 21st, 2008 @ 12:08 PM
Hi,
The following code doesn't work as expected :
var style = {};
style.width = 12;
style.height = 34;
style.top = 56;
style.left = 78;
$('whatever').setStyle( style );
Why ? Cause styles cannot be integers, but have to be strings !!!
Instead, I should have written :
var style = {};
style.width = 12 + 'px';
style.height = 34 + 'px';
style.top = 56 + 'px';
style.left = 78 + 'px';
$('whatever').setStyle( style );
It could be great that int would be understood as a pixel length...
Comments and changes to this ticket
-
Nick Stakenburg May 21st, 2008 @ 01:35 PM
I think it works just fine, you need to set px/pt/em/etc like you would using CSS. Since px is not the only unit I wouldn't default to anything. Just set your style with strings.
$('foo').setStyle({ width: '4px', height: '3px', top: '2px', left: '1px' }); -
Tobie Langel May 21st, 2008 @ 02:26 PM
- → State changed from new to invalid
-

Julien Garand May 22nd, 2008 @ 08:20 AM
Ok, you're right... sorry for that
On Wed, May 21, 2008 at 1:36 PM, Lighthouse
wrote:
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
