473,804 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with DOM script (Error: contents.style has no properties)

I've got a script where I'm trying to toggle the visibility of a div
node by a click on an image that is the sibling of the div.

So I've got this HTML:

<div>
<img src="RightPoint ingTriangle.gif " onclick="opencl ose(this);">
<span class="title">t itle</span>
<div class="contents ">
Hi. This is the contents.
</div>

<div class="children ">
</div>
</div>

And this javascript:

function openclose(imgem t)
{
if(imgemt.src.i ndexOf("RightPo intingTriangle. gif") > -1)
{
imgemt.src = "DownRightPoint ingTriangle.gif ";
imgemt.src = "DownPointingTr iangle.gif";
parent = imgemt.parentNo de;
//find the parent of the image element
contents = parent.childNod es[2];
//get the child of that element that is a
//div with the class contents

//alert("contents :" + properties(cont ents));
contents.style. visibility = 'visible';
}
else
{
imgemt.src = "DownRightPoint ingTriangle.gif ";
imgemt.src = "RightPointingT riangle.gif";
parent = imgemt.parentNo de;
//find the parent of the image element
contents = parent.childNod es[2];
//get the child of that element that
//is a div with the class contents

alert("contents :" + contents);
contents.style. visibility = 'hidden';
}
}
The problem I'm seeing seems to be that when I try to set
contents.style. visibility to 'visible' or 'hidden', I get
the following error:

Error: contents.style has no properties
Source File: http://weston.canncentral.org/misc/sheesh/test.html
Line: 16

Why would this be the case, and how could I fix it?

The test page is viewable on the net, by the way, at:

http://weston.canncentral.org/misc/sheesh/test.html
Jul 20 '05 #1
1 1882
Rostov wrote on 13 Dec 2003 at Sat, 13 Dec 2003 23:52:39 GMT:
I've got a script where I'm trying to toggle the visibility of a
div node by a click on an image that is the sibling of the div.

So I've got this HTML:

<div>
<img src="RightPoint ingTriangle.gif "
onclick="opencl ose(this);"> <span
class="title">t itle</span> <div class="contents ">
Hi. This is the contents.
</div>

<div class="children ">
</div>
</div>
You're not getting the correct node. Using your hosted (not posted)
code: in IE, the fifth child (index 4) is the contents class DIV, and
it's the sixth (index 5) in Opera. Browsers interpret the whitespace
between elements differently. You'll either have to find another way
to walk through the tree, use IDs, or restructure you HTML to:

<div<img src="RightPoint ingTriangle.gif " onclick="opencl ose(this);"
<span class="title">t itle</span
<div class="contents "
Hi. This is the contents.</div
<div class="children "
</div
</div>


This way, there's no white-space between elements, so the contents
class DIV is the third child (index 2) in both IE and Opera. However,
the HTML isn't as easy to read[1].

Mike
[1] I sometimes resort to this, though more limited in scope, when
style sheets render rogue highlights, text decoration and such.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #2

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

Similar topics

8
3690
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function and passes it two parameters. For the life of me I cannot figure out what the error is, but one occurs everytime I click a &%*$&# radio button. Also, the function only alerts the user immediately as to what question/answer they clicked. I am...
8
2571
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating an alternative to pop-up windows in a web page. The code I have works (sort of). The problem is that I can move these layers around when I move the mouse slowly, however, if I move it fast the web browser looses track of the motion and leaves the...
11
1927
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into this HTML file, all is OK but whenever the functions are separated (as it is now), when I run the page, I get the following error: Line 73, object expected.
1
4760
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I have a page in a folder (under anonymous authentication in IIS6) that has a link on it that...
5
3513
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything works fine as it also does in firefox if I call the contents frame directly (i.e. outside of its frameset). However, if I call my main page (index.html) which invokes the frame set, the contents frame javascript menubar onmouseover function...
11
1928
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is that in the swapcheck(x) function below, if I uncomment the first line (commented with //) the whole thing brings and IE errors the page with an object expected error on line (whichever input control I clicked).
2
2185
by: verci | last post by:
Hi guys, sorry if this seems stupid but I'm a newbie, I'm running Windows XP Pro SP2, IE 7, VS2005, ASP.net 2.0 The problem is that I'm trying to display this news scroller made in a Javascript file(newsscroller.js) in my ASP page, everything works great in a normal HTML page, I can see the scroller just fine, but in an ASP page it just does not show, I get some error message that the control has not been initialize, so far I've been...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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
10317
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
10075
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...
1
7615
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
6851
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();...
1
4295
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
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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.