i just need access to a divs css "left" property.. thats all, i just want to dynamically control its horizontal position.. why doesnt this work?:
var moveMe = document.getElementById("divToMove");
function moveDiv()
{
moveMe.style.left = "300px";
}
this is a simplication of my real code.
Ive got it so a rollover correctly triggers the moveDiv function..
im so confused and i have a deadline... i havent used js for css manipulation before, google keeps telling me to use the farken getElementById thing and refer to css properties by object.style.cssporoperty, but it doesnt work!!!!!!
The Time Through Ages
In the Name of Allah, Most Gracious, Most Merciful
1. By the Time,
2. Verily Man is in loss,
3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.
it's mandatory that you use position:absolute or position:relative before you can move the elements around the page. you can declare it in the css, or you can dynamically change it using javascript, you should also declare your functions at the end of your page above </body> instead of in the head in most cases:
function moveDiv()
{
moveMe.style.position = "absolute";
moveMe.style.left = "300px";
}
by the way both versions of your code worked for me, this is a 3rd version,
i moved the position absolute/relative from within the css code, and use javascript
to set the position property dynamically from within the function, you can do it dynamically
in case you don't know which elements will be moved in advance, or in case you just
don't want to add it to every element in css, as javascript can apply it only when needed
instead of hardcoding it everywhere to keep the file size down, although you can apply
it to multiple elements at the same time with css too
bilgi notu: kod böyle de çalıştı
#divToMove { position:relative;
böyle de
moveMe.style.position = "relative";
Last edited by Ayşe; 06-20-2012 at 04:45 PM.
The Time Through Ages
In the Name of Allah, Most Gracious, Most Merciful
1. By the Time,
2. Verily Man is in loss,
3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.
Bookmarks