jQuery , / :
HTMLElement.prototype.toggleDisplay = function(on_or_off, display_type) {
if (typeof(tddisptype) == "undefined") tddisptype = "block";
var new_display;
if (typeof(on_or_off) != "boolean") {
if (this.style.display == "none") new_display = display_type;
else new_display = "none";
} else {
if (on_or_off) new_display = display_type;
else new_display = "none";
}
this.style.display = new_display;
}
This adds the toggleDisplay () function to all elements; for example, those that you can get through document.getElementById (). You can pass it trueeither falseas a parameter to show or hide the element, or if you do not pass the parameter to it, it will try to figure out, show or hide the element. The second argument indicates the type of display associated with the "on" state; above, by default it is equal block.
source
share