Link to home
Start Free TrialLog in
Avatar of Dutch_guy
Dutch_guy

asked on

Change existing javascript, hide/unhide thing

I use this simple script to hide/ unhide some content:

http://webdesign.about.com/od/dhtml/a/aa101507.htm

With this script I have two buttons. They both can hide/ unhide some content. My problem is that if button A is selected and I click again on button A, the content disappears. I want it that it always show default content.

Basically I want that if I click on Button A, it must not be possible to click on it again. Because that would make the content disappear.
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

if you don't want that link to be clickable again, then why dont you simply remove the href attribute and onclick event handler from that link

you can either do
document.getElementById("linkId").href = null;
or
document.getElementById("linkId").removeAttribute("href",1);
check this link http://www.roseindia.net/javascript/javascript-removeattribute-method.shtml

you can later put the link back again using addAttribute (like second one) or simply assigning the attribute value later (like first one)
ASKER CERTIFIED SOLUTION
Avatar of animesxplosion
animesxplosion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use a function like this...

function Toggle(buttonId)
{
      var button = document.getElementById(buttonId);
      if(button.disabled == false)
              button.disabled = true;
      else
              button.disabled = false;
}

-Ajitha

Avatar of Dutch_guy
Dutch_guy

ASKER

Sorry, I didn't realize I made a mistake in my question.

I'm not using buttons, but images, like this:

<a href=javascript:unhide2('switch1');javascript:hide('switch2');><img src="images/tab_aanbiedingen.gif" /></a>

So the above solutions will not work since it is not a button. Any idea's ?

@Dutch_guy: Did you tried what i suggested?
I have not talked about buttons.

Thanks
Could you explain it a bit more, beacuse I know very little of Javascript...
I had simply suggested that you remove href/onclick attribute from the link.
in other words,
<a href="" onclick="">.....<!--Inside the link, it could be text, div, or an image -->... </a>

if you remove href and onclick attributes, then it will become.

<a>.....<!--Inside the link, it could be text, div, or an image -->... </a>

which is actually not a link.

Then later on you can add these attributes back if you want.

Thanks
Looks like this is what I need. Could you provide the script ? I have no idea how to implement this.
Please use the following as reference

<script>

   function removeLink(linkObj)
   {
         linkObj.href = null;
         linkObj.onclick = null;
   }

   function addLink( linkObj )
   {
       objLink.href = ""; \\add the href property
       objLink.onclick = ""; \\add the onclick event handler
   }

</script>

<a href="javascript:removeLink(this)" onclick="removeLink(this)">

I eventually changed the button to an image and went for animesxplosion's solution. Works great !