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
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
Share Improve this question edited Sep 30, 2021 at 19:44 j08691 208k32 gold badges268 silver badges280 bronze badges asked Sep 1, 2015 at 6:31 Vishnuprabhu GopalakrishnanVishnuprabhu Gopalakrishnan 1231 gold badge2 silver badges12 bronze badges 4 |3 Answers
Reset to default 12Use 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'});
A simple solution to this issue that was not addressed. Remove the following from the top of your html file that is using the script:
<!DOCTYPE HTML>
I dont know what that reason.. and you can add to CSS code a class for ex:
HTML Code
<div id="div"> <p> abcd </p></div>
CSS Code
.edit-left {left: 0 ;}
JS
const handleClickProjects = () => {
console.log("click")
let element= document.getElementById("div");
if (element.classList.contains("edit-left")) {
element.classList.remove("edit-left")
}
else {
element.classList.add("edit-left")
}
}
This for ReactJS. For pure JS use addEventListener.... (this code has a default left arg)
ifrmObj.style.left = 100 + 'px';
– Tushar Commented Sep 1, 2015 at 6:31