I have no idea what your showhide.js file is doing, I’ll also assume you are calling it with the correct paramaters (without seeing it, it is hard to know) but try this:
<div id="wrapper">
<a onclick=”switchMenu(’showhide’);”>What’s New</a>
<div id="showhide">
<?php include(TEMPLATEPATH . '/whatsnew.php'); ?>
</div>
</div>
You had regular html inside javascript tags which is why you didnt see the anchor text.
Hope that gives you some insight.
Regards,
Drew
If you’re using the onclick event on an A tag, you will still need to add a HREF onto it…
<a href="#" onclick="switchMenu('showhide');">What’s New</a>
One drawback however is that you have to enter something into the HREF, and using # will cause the browser window to shoot to the top…
If you don’t want that to happen, attach the onclick event to a different tag, an image would be suited.
I use a small script for showing and hiding elements to, so i know the above to be true assuming the script works much the same as my own…
Of course if you must use a link then you can use an anchor to keep it around the same area of the page…
<a name="thisanchor"></a><a href="#thisanchor" onclick="switchMenu('showhide');">What’s New</a>
Thanks guys. t31os, I added href=”#” but did not see the anchor until I removed the scrips tag ‘<script type=”text/javascript”>’ as drew suggested. However clicking the anchor has no effect 🙁
Drew my showhide works fine in normal html and is as follows:
function switchMenu(obj) {
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
I use…
function togglebox(id)
{
var e = document.getElementById(id);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
Then in my HTML i have something like this…
<div class="example" id="hidethis">Some content to be hidden....</div>
<a href="#" onclick="togglebox('hidethis')">my toggle link</a>
In the CSS..
.example {display:none}
Of course this assumes the standard state of the element is hidden, and the onclick event shows that hidden element…
I also have a second function in that file… like so..
function togglebox2(id)
{
var e = document.getElementById(id);
if(e.style.display == 'inline')
e.style.display = 'none';
else
e.style.display = 'inline';
}
So depending on the type of element i call the relevant inline or block toggle function.
Like i said, it does work better without using a link to toggle…
<img src="someimage" onclick"togglebox('hidethis')" />
My script is called into my theme via a custom field, which ultimately just does an inline include of the JS file which i’ve plonked into my theme folder….
Of course make sure the script is run/included.. before the link and element to hide…
@t31os – oh yeah! Works like a charm. With the php include as well! Absolutely fab.
Thanks a lot,
Tom.