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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use a function like this...
function Toggle(buttonId)
{
var button = document.getElementById(bu ttonId);
if(button.disabled == false)
button.disabled = true;
else
button.disabled = false;
}
-Ajitha
function Toggle(buttonId)
{
var button = document.getElementById(bu
if(button.disabled == false)
button.disabled = true;
else
button.disabled = false;
}
-Ajitha
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('s witch1');j avascript: hide('swit ch2');><im g src="images/tab_aanbieding en.gif" /></a>
So the above solutions will not work since it is not a button. Any idea's ?
I'm not using buttons, but images, like this:
<a href=javascript:unhide2('s
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
I have not talked about buttons.
Thanks
ASKER
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
in other words,
<a href="" onclick="">.....<!--Inside
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
ASKER
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:removeLin k(this)" onclick="removeLink(this)" >
<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:removeLin
ASKER
I eventually changed the button to an image and went for animesxplosion's solution. Works great !
you can either do
document.getElementById("l
or
document.getElementById("l
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)