Sunday, January 21, 2007

[code] Using Javascript to hide / unhide

init:function MarkSection () {
if(document.getElementById('HideTarget')){
/* Hide target */
var HideTarget = document.getElementById('HideTarget');
HideTarget.style.display = 'none';

/* Add onclick function on trigger to hide or unhide target */
var TriggerTarget = document.getElementById('TriggerTarget');
TriggerTarget.onclick = function() {
var HideTarget = document.getElementById('HideTarget');
if (HideTarget.style.display == 'none') {
HideTarget.style.display = 'block';
this.style.backgroundImage = "url('TargetOn.gif')"
} else {
HideTarget.style.display = 'none';
this.style.backgroundImage = "url('TargetOff.gif')"
}
} // end: onclick function
} // end: if guidebody
} // end: function

addEvent(window, 'load', MarkSection.init)

function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}


Reference: http://www.enterprisetrucks.com/include/faq.js

No comments:

Post a Comment