I'm a little bit new to 开发者_如何学GoJavaScript, but I hope someone can help me.
How can I get the height of a paragraph element or div? By height I don't mean how high it is, but how many pixels it is sitting from the very top of the page. Is there any way to get this value?
And to the 2nd part of my question: how can I set this specific value to another element?
Thank you!
This is usually called an offset (left or top) depending on the axis. Most people prefer to use a JS framework instead of writing pure javascript themselves. You might want to give jQuery a try, it's the most popular nowadays.
Here is the documentation for the offset() method in jQuery:
http://api.jquery.com/offset/
Access the style through DOM:
http://www.universalwebservices.net/web-programming-resources/javascript/modify-css-with-javascript
Second question - see this example
Basically you modify the DOM through JS:
function changeBorder()
{
document.getElementById('myTable').border="10";
}
精彩评论