Jump to content

Click Menu Problem


chibineku
 Share

Recommended Posts

I am trying to get a click nav menu working, but I'm having a few problems.I originally had a bit of JavaScript that, with the aid of PHP, detected which page was currently being viewed and set the id of the appropriate menu list item to 'cur', so that it would attract the correct styling from CSS. Now I've changed the menu from a drop down one to a click menu. The click menu works, except that the list item with the id 'cur' flashes into view and then disappears. Using FireFox Firebug, if you look at the HTML, the content, closing </li> tag and classname are missing for this element (in the sample page I'll provide a link to, the current page is 'content', so this is the missing tag). It's a really long bit of script, CSS and HTML, so I'll not paste it here unless someone asks, instead I hope whoever can help views the source.Here's the page.

Link to comment
Share on other sites

I have made a little progress. The JavaScript that sets the current page list item with the id 'cur' does so by recreating the element and it's children and swapping the new one, with it's shiny new 'cur' id, for the old one. On examining the source in Firebug, it became clear that the className wasn't being set because, well, I hadn't told it to. So the problem seems to be with the JavaScript not faithfully replicating all of the child nodes of the list element.

Link to comment
Share on other sites

Okay, more:I changed the JavaScript from:function setCurPage() {var CurPage = "<?php echo $_SERVER["PHP_SELF"]; ?>";var CurRaw = CurPage.substr(1);var Cur = CurRaw.split(".")[0];var oldNode = document.getElementById(Cur);var newNode = document.createElement("li");newNode.id = "cur";newNode.className = "sub unclick";var innards = oldNode.children;while(innards.length > 0) {newNode.appendChild(innards[0]);}oldNode.parentNode.replaceChild(newNode, oldNode); clickMenu('menu');}to:function setCurPage() {var CurPage = "<?php echo $_SERVER["PHP_SELF"]; ?>";var CurRaw = CurPage.substr(1);var Cur = CurRaw.split(".")[0];var oldNode = document.getElementById(Cur);var newNode = document.createElement("li");newNode.id = "cur";newNode.className = "sub unclick";var innards = oldNode.parentNode.children;while(innards.length > 0) {newNode.appendChild(innards[0]);}oldNode.parentNode.replaceChild(newNode, oldNode); clickMenu('menu');}And now FireFox gives me this error:Node cannot be inserted at the specified point in the hierarchy" code: "3[break on this error] oldNode.parentNode.replaceChild(newNode, oldNode);\r\nI'm not entirely sure I understand the problem.

Edited by chibineku
Link to comment
Share on other sites

This new leave-em-alone-til-they-sort-it thing works :) I have succeeded! I think...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...