|
First, heres the main script that does all the work next, you need to put a hide/show link. example: next the div that will show or hide: example: Comes in handy... well at least it has to me enjoy.
|
k
|
|
|
|
Very useful indeed, however you can simplify the ShowMore() function a little
function showMore(whichid) { if (ie5||ns6) { var showid = document.getElementById(whichid); } if (showid.style.display == 'none') { showid.style.display = ''; } else { showid.style.display='none'; } }
You can use a one-line conditional instead of an if/then/else statement. Observe...
function showMore(whichid) { if (ie5||ns6) { var showid = document.getElementById(whichid); } showid.style.display = (show.id.style.display == 'none') ? '' : 'none'; }
That states that if showid's style is equal to not be shown, allow it to be shown.
|
wat
|
|
|
|
Simplify it further. Do we need to know if its ie5 or ns6? No. It just has to support "document.getElementById" <script type="text/Javascript"> function showMore(whichid) { if(!document.getElementById) return false; var showid = document.getElementById(whichid); showid.style.display = (showid.style.display == "none"?"":"none"); } </script> Personally, I'd find it easier to pass the element to be changed to the function via a parameter. <script type="text/Javascript"> function showMore(ext){ if(ext) ext.style.display = (ext.style.display == "none"?"":"none"); } </script> Just my two cents. Also, its good considering you're still learning.
|
|
|
|
|
Good and simple script for a newbie coder like me
|
Ex-admin, designer and founder of Studio Zero. Currently working as a Dentist
|
|
|
|
Good and simple script for a newbie coder like me thats what i said!
|
k
|
|
|