473,606 Members | 2,115 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 26575
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
4594
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
22061
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 valign="baseline"><a href="#" onclick="(document.body.style.zoom)?...
6
3366
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
11835
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
6993
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
5593
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
13883
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: document.getElementById('el').style.padding-left = '5px' will throw 'invalid assignment left-hand side', as expected.. Any help...
7
8091
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
7942
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8084
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8300
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6761
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5963
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1287
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.