473,583 Members | 3,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in document.getEle mentById(id).st yle.background-position = "-200px -500px"?

Hello,

In my script, the line

document.getEle mentById(id).st yle.background-position = "-200px -500px";

fails !

So, how can I change the background-position value ?

Thanks, Denis

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator " CONTENT="EditPl us">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Descripti on" CONTENT="">

<style>
div.hr {
border: solid #0000FF;
display: inline;
height: 600px;
width: 300px;
background-image: url(plan_statio n.gif);
background-repeat: no-repeat;
background-position: -100px -400px;
margin: 0em 0 0em 0;
}

</style>

<SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">

function goRight(id)
{
document.getEle mentById(id).st yle.height="100 px";
document.getEle mentById(id).st yle.background-position = "-200px -500px";
}

</SCRIPT>
</HEAD>
<BODY>
<a href="#" onclick="goRigh t('myDiv')">rig ht</a>
<DIV id="myDiv" class = "hr" ></DIV>
</BODY>
</HTML>
Jul 23 '05 #1
4 26569
Ghyslaine Crespe wrote:
Hello,

In my script, the line

document.getEle mentById(id).st yle.background-position = "-200px -500px";


[snip]
With hyphenated style properties you are usually meant to refer to them
in code by dropping the hyphen and capitalising the next word (the
intercapitalisa tion system). In your case, "background-position" becomes
"backgroundPosi tion"

Andrew Poulos
Jul 23 '05 #2
On Sun, 26 Dec 2004 00:40:08 +0100, Ghyslaine Crespe
<gh************ **@worldonline. fr> wrote:

[snip]
So, how can I change the background-position value ?
Whilst background-position is the correct property name in CSS, it's an
illegal identifier in ECMAScript. You're looking for backgroundPosit ion.

[snip]
background-image: url(plan_statio n.gif);
background-repeat: no-repeat;
background-position: -100px -400px;
Be careful when specifying a background image without a background colour.
Make sure that the foreground content is still easily viewable if images
are disabled.
margin: 0em 0 0em 0;
That should be reduced to

margin: 0;

[snip]
<SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">
The language attribute is deprecated and besides, specifying the
(required) type attribute makes it redundant.
function goRight(id)
{
document.getEle mentById(id).st yle.height="100 px";
document.getEle mentById(id).st yle.background-position
= "-200px -500px";
It would be more efficient to save a reference to the element, rather than
look it up twice:

var style = document.getEle mentById(id).st yle;
style.height = '100px';
style.backgroun dPosition = '-200px -500px';

Preferably, it would include feature detection. Something like

var obj, style;
if(document.get ElementById && (obj = document.getEle mentById(id))
&& (style = obj.style))
{
style.height = '100px';
style.backgroun dPosition = '-200px -500px';
}

[snip]
<a href="#" onclick="goRigh t('myDiv')">rig ht</a>


If you don't cancel the click event here, the vertical position of the
document may change:

onclick="goRigh t('myDiv');retu rn false;"

Hope that helps,
Mike
Merry Christmas

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Yes, it helps me a lot. Thanks for all these clues!

Denis

"Michael Winter" <M.******@bluey onder.co.invali d> a écrit dans le message de
news:opsjk97azv x13kvk@atlantis ...
On Sun, 26 Dec 2004 00:40:08 +0100, Ghyslaine Crespe
<gh************ **@worldonline. fr> wrote:

[snip]
So, how can I change the background-position value ?


Whilst background-position is the correct property name in CSS, it's an
illegal identifier in ECMAScript. You're looking for backgroundPosit ion.

[snip]
background-image: url(plan_statio n.gif);
background-repeat: no-repeat;
background-position: -100px -400px;


Be careful when specifying a background image without a background colour.
Make sure that the foreground content is still easily viewable if images
are disabled.
margin: 0em 0 0em 0;


That should be reduced to

margin: 0;

[snip]
<SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">


The language attribute is deprecated and besides, specifying the
(required) type attribute makes it redundant.
function goRight(id)
{
document.getEle mentById(id).st yle.height="100 px";
document.getEle mentById(id).st yle.background-position
= "-200px -500px";


It would be more efficient to save a reference to the element, rather than
look it up twice:

var style = document.getEle mentById(id).st yle;
style.height = '100px';
style.backgroun dPosition = '-200px -500px';

Preferably, it would include feature detection. Something like

var obj, style;
if(document.get ElementById && (obj = document.getEle mentById(id))
&& (style = obj.style))
{
style.height = '100px';
style.backgroun dPosition = '-200px -500px';
}

[snip]
<a href="#" onclick="goRigh t('myDiv')">rig ht</a>


If you don't cancel the click event here, the vertical position of the
document may change:

onclick="goRigh t('myDiv');retu rn false;"

Hope that helps,
Mike
Merry Christmas

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #4
Ghyslaine Crespe wrote on 26 dec 2004 in comp.lang.javas cript:
document.getEle mentById(id).st yle.background-position


document.getEle mentById(id).st yle.backgroundP osition
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #5

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

Similar topics

6
4591
by: linuxnooby | last post by:
Hi I want a form field to be selected when the page loads. But I get the error message Error: document.getElementById("ff") has no properties any ideas what I am doing wrong? code below
4
22060
by: jnag | last post by:
Hello, Through an onClick() event, I have an inline function to change the font size of the page (actually, I need to do this for the entire website). I have this defined in the header.cfm file as: onclick="document.body.style.fontSize='50%';" This does not work at all for some reason. Whereas,
3
15588
by: jnag | last post by:
I am trying to implement font changer, where I have links on the banner of the site and when the user clicks on the links, the font size of the page has to change. I tried document.body.style.fontSize='50%' for example, on an onclick() event, but it did not work. I tried zooming with the following code, and it works: <td...
6
3363
by: therig | last post by:
I'm having issues, I've spent many hours searching and I'm a noob at javascript, any help will be greatly appreciated. I keep getting the following error: Error: document.forms.sec11_A has no properties with this script: function checkform(btntype) {
2
11834
by: dheerajkoli | last post by:
hello friends , i m getting a problem on when i compiling a my project in vc++6.0 error C2274: 'function-style cast' : illegal as right side of '.' operator. please help me . if any hint u send me on following email ID xxxxxxxx@xxxxx.xxxx
4
2015
by: manjugi | last post by:
Hi, I am running som web application at some point i have one web page contains some buttons,text field etc.when i click on button it gives an error message stating that "error: 'document.layers.main is null or not an object" what i want is what this error message indicates.
3
6992
by: shiks1305 | last post by:
this js function is giving javascript error: document.forms.elements is null or not an object function DisableText() { var count = document.forms.elements.length; for (i=0; i<count; i++) { document.forms.elements.disabled=false; }
8
5591
by: ananjy | last post by:
Hi when i m trying to execute my ajax code using a link to display datas from another page named second.php., i got an error when the page loads in "ie"., which runs perfectly in firefox., here is my code <script type="text/javascript"> var i;
2
13882
by: jmatos | last post by:
I need to change the style of an element changing its padding-left property (got it in firefox but IE is a different battle..). I can use document.getElementById().style.XX to everything i need, except with padding-left, as it is separated by a ' - ' and it is not correct to use it as it was supposed to: ...
7
8089
by: sunny1009 | last post by:
Hi Guys, Can you please check this code and see whats wrong with it?? I am getting document.all.style is null or not an object error. Any help will be really appreciated. Thanks Code function toggleDiv(id,flagit) {
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.