JavaScript retrieving element's CSS values -


i'm making basic drag , drop system , need retrieve top , left properties of element being moved. if this:

var mover = document.getelementbyid('mover'); alert(mover.style.top); 

will alert nothing ( ' ' )

is there way of retrieving css values (in js) without having define them js first?

you need use getcomputedstyle if wish retrieve properties computed rather defined.

https://developer.mozilla.org/en-us/docs/web/api/window/getcomputedstyle

from mdn link...

<script>   function getthestyle(){     var elem = document.getelementbyid("elem-container");     var thecssprop = window.getcomputedstyle(elem,null).getpropertyvalue("height");     document.getelementbyid("output").innerhtml = thecssprop;    }   getthestyle(); </script> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -