Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript element.style.left Not working

Setting element top,left via javascript stops working,Perviously it was working perfectly.

ifrmObj.style.left = 100;
ifrmObj.style.top = 150;

Now i have to add a 'px' with number. What is the change that i made is the reason for this issue

like image 967
Vishnuprabhu Gopalakrishnan Avatar asked Sep 01 '15 06:09

Vishnuprabhu Gopalakrishnan


1 Answers

Use position first then left or top will work like,

Syntax:

object.style.position="static|absolute|fixed|relative|initial|inherit" 

For egs,

ifrmObj.style.position='absolute';//relative or fixed

To add px in your numbers,

For static numbers

ifrmObj.style.left = '100px';
ifrmObj.style.top = '150px';

For variables numbers

var x=100,y=150;
ifrmObj.style.left = x+'px';
ifrmObj.style.top = y+'px';

And if you are using jquery then use css() in one go like,

$(ifrmObj).css({'left':'100px','top':'150px','position':'absolute'});
like image 69
Rohan Kumar Avatar answered Sep 17 '22 18:09

Rohan Kumar