473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Simple question about getting value from CSSStyleDeclaration

Hello, here is my short example ready to paste. Just one style script
and some body. I just wanted to see the value of style.left,
but why it isn't working. I am wondering a lot of time what is wrong
but i failed so please be so kind and help me.

-------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#myDiv
{
position:absolute;
width: 100px;
height: 100px;
top: 150px;
left: 250px;
border: 1px solid black;
background-color: #339966;
}
</style>
<script type="text/javascript">
<!--

function showLeft()
{
document.getElementById('paragraph').innerHTML =
document.getElementById('myDiv').style.left;
document.write( 'left = ' );
}
//-->
</script>
</head>

<body onload="showLeft()">
<p id="paragraph"></p>
<div id="myDiv"></div>
</body>
</html>
-------------------------------------------------------------------
Mar 21 '07 #1
4 4552
Soren wrote:
Hello, here is my short example ready to paste. Just one style script
and some body. I just wanted to see the value of style.left,
but why it isn't working.
element.style.left gives you the inline style that is the style set with
the style attribute e.g.
<div style="left:200px;">
or with script itself (element.style.left = '200px';) but your example
document does not set the inline style.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 21 '07 #2
Martin Honnen wrote:
Soren wrote:
>Hello, here is my short example ready to paste. Just one style script
and some body. I just wanted to see the value of style.left,
but why it isn't working.

element.style.left gives you the inline style that is the style set with
the style attribute e.g.
<div style="left:200px;">
or with script itself (element.style.left = '200px';) but your example
document does not set the inline style.
ok I understand but the question remains. How can i get the value from
the div not knowing its properities ?
Mar 21 '07 #3
On Mar 21, 7:00 am, Soren <java...@tlen.plwrote:
Hello, here is my short example ready to paste. Just one style script
and some body. I just wanted to see the value of style.left,
but why it isn't working. I am wondering a lot of time what is wrong
but i failed so please be so kind and help me.
martin told you the reason. here is how to get the value of left-

this will return the value of left defined in 1st stylesheet>1st rule.

function returnLeft() {
var d=document,Element
Element=d.getElementById('paragraph')
var style=d.styleSheets[0]
var rules=style.cssRules||style.rules
return rules[0].style.left
}

OR____

function showLeft() {
var d=document,Element,Element2,style
Element=d.getElementById('paragraph')
Element2=d.getElementById("myDiv")
style=Element2.currentStyle||getComputedStyle(Elem ent2).style
Element.innerHTML=
"left="+Element2.currentStyle.left
}

Mar 21 '07 #4
On Mar 21, 7:45 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
I just wanted to see the value of style.left,
but why it isn't working.

function showLeft() {
var d=document,Element,Element2,style
Element=d.getElementById('paragraph')
Element2=d.getElementById("myDiv")
style=Element2.currentStyle||getComputedStyle(Elem ent2).style
Element.innerHTML=
"left="+Element2.currentStyle.left

}
change that function to-

function showLeft() {
var d=document,Element,Element2,style
Element=d.getElementById('paragraph')
Element2=d.getElementById("myDiv")
style=Element2.currentStyle||getComputedStyle(Elem ent2)
Element.innerHTML=
"left="+style.left
}

Mar 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
1
by: timothy ma and constance lee | last post by:
Sir I have the simple question as follows: I got three pages a,b,c point to same page d when clicking submit. Is there any way, by using JavaScript to trace back which page a or b or c to...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
5
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
30
by: Brian Elmegaard | last post by:
Hi, I am struggling to understand how to really appreciate object orientation. I guess these are FAQ's but I have not been able to find the answers. Maybe my problem is that my style and...
6
by: listerofsmeg01 | last post by:
Hi, When specifying say, background color in CSS, I use: background-color:red; However, after much head scratching when trying to set it dynamically via the DOM, I found I need to spell it...
7
by: Dustin MacDonald | last post by:
Hi everyone. This is my first time posting to this newsgroup, and although I maintain my netiquette I might've missed something specific to the newsgroup, so hopefully you can avoid flaming me...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.