Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Visibility Toggle

Status
Not open for further replies.

DigitalBoy

Programmer
Oct 11, 2000
87
US
Fellow Developers,

I'm looking for a simple script that will allow a user to toggle the visibillity of an image based on a onClick function call. Does anyone know where I can quickly find one?

Thanks,

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
What browsers are you supporting? jared@aauser.com
 
Um ... I'm not quite sure how to answer that. See, I'm developing this application for television, so technically, the browser that I'm developing for is the Liberate Technologies platform. It should support most of what IE supports, but that's still not been tested.

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
well, this works in IE:

<script>
function toggleVis(obj)
{
var st = obj.style
st.visibility=(st.visibility=='visible'||st.visibility=='')?'hidden':'visible';
}

</script>
<img id=&quot;benluc&quot; onclick=&quot;toggleVis(this)&quot;>
<button onClick=&quot;toggleVis(benluc);&quot;>Show/Hide</button> jared@aauser.com
 
Do you reckon this would cross browsers?I like the idead of sending an object, the reason I have never before is that I thought you would need to send it's full 'path', document.all etc, but this is very good, saves having to use eval on strings.

function toggleVis(obj)
{ var IE =(document.all)?true:false;
var st = obj.style
if(IE){
st.visibility=(st.visibility=='visible'||st.visibility=='')?'hidden':'visible';
}

else if(!IE){
obj.visibility =(obj.visibility=='show'||obj.visibility =='')?'hidden':'show';
}
}

have not tested it, just mucking around!



&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
I am a fool...man submission happens very quickly!

function toggleVis(obj)
{ var IE =(document.all)?true:false;
var NNobj = document.layers.obj;
var st = obj.style;
if(IE){
st.visibility=(st.visibility=='visible'||st.visibility=='')?'hidden':'visible';
}

else if(!IE){

NNobj.visibility =(NNobj.visibility=='show'||NNobj.visibility =='')?'hidden':'show';
}
}

have not tested it, just mucking around!



&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
cool, bangers, but you don't need this part:

else if(!IE){

because you just checked the browser above.
Nice crossbrowser script though!
jared@aauser.com
 
Just for thsoe Opera users (not).. BB &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
Ok, I tried burying this in an anchor tag, but I seem to have run into some errors (BTW, I did try the code as it is seen above, and I was able to toggle the image &quot;off&quot; but not &quot;on&quot; ... yet):

<a id=&quot;rate&quot; href=&quot;javascript:eek:nClick=toggleVis(this)&quot;><img src=&quot;images/icon_rte.gif&quot; width=&quot;24&quot; height=&quot;24&quot; border=&quot;0&quot;></a>

Any help would greatly be appreciated.

- DB



dgtlby@excite.com
Administrator

UBB Developers Network

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top