View Single Post
Old 01-14-2013, 12:57 AM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Sorry, I thought you meant the position property (absolute, etc.).

The value from an input is always text (a string) initially, so you need to convert it to a number; multiplying by 1 is one way to do this:

Code:
		 if(property == 'top') {
            $('#testDiv').css("top",(value * 1));
        }
		else if(property == 'left') {
            $('#testDiv').css("left",(value * 1));
        }
You might want to add pixels as well, to ensure it will work in all browsers, although, these days, it probably will anyway:

Code:
		 if(property == 'top') {
            $('#testDiv').css("top",(value * 1) + 'px');
        }
		else if(property == 'left') {
            $('#testDiv').css("left",(value * 1) + 'px');
        }
The height() and width() jQuery methods will automatically convert to a number, which is why these were working.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote