• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hiding child element - IE works, but Mozilla no

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm trying to do expandable javascript tree view, but it does not work with mozilla and netscape. Can someone help me which way do i have to modify the javascript code ?
Here is my example:
MS IExplorer has no problems expanding and collapsing the tree after clicking on the text SUB, but what about Mozilla or Netscapoe ?
My problem is, i can't use getElementById, because in my document are more tags with the same id. I have to lookup in <li> childs, there can be only one tag with the id.
TREEVIEW.HTML:
<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function clickHandler() {
var targetId, srcElement, targetElement;
//this one may be IE specific, but i think something else is also
srcElement = window.event.srcElement;
if (srcElement.className == "Outline") {
targetId = srcElement.id + "d";
childs = srcElement.childNodes;
for(i=0; i<childs.length; i++) {
if (childs[i].id == targetId) {targetElement = childs[i];}
}
if (targetElement.style.display == "none") {
targetElement.style.display = "";
} else {
targetElement.style.display = "none";
}
}
}
document.onklick = clickHandler; //onklick= o n c l i c k
</SCRIPT>
<ul id="rootd">
<li class="Outline" id="sub1">SUB1
<ul id="sub1d">
<li>nod1
<li>nod2
<li class="Outline" id="sub2">SUB2
<ul id="sub2d">
<li>nod4
<li>nod5
<li>nod6
</ul>
<li>nod3
</ul>
<li class="Outline" id="sub2">SUB2
<ul id="sub2d">
<li>nod4
<li>nod5
<li>nod6
</ul>
<li class="Outline" id="sub3">SUB3
<ul id="sub3d">
<li>nod4
<li>nod5
<li>nod6
</ul>
</ul>
</body>
</html>
Regards
Mir
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i can't use getElementById, because in my document are more tags with the same id.


Did you consider fixing this? It's no wonder things aren't working correctly. You are creating an invalid document. I think that your time would be better spent fixing the document than trying to patch work-arounds that may or may not work across the various browsers.
hth,
bear
 
Mir Ricco
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it's one possibility, i can set unique id, which can be very long when the tree is big, because it should reflect the element path from the root.
But i wanted to know if the other aproach is also possible.
Isn't it possible to go through child nodes in every browser ?
Regards
Mir
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic