Login
Hauptmenü
Willkommen, Gast
Benutzername: Passwort:

THEMA: Display / Hide Div with Javascript by click

Display / Hide Div with Javascript by click 3 Jahre 9 Monate her #1

  • davidduckwitz
  • davidduckwitzs Avatar
  • Offline
Today i want to show you, how you can hide or show a Div with Javascript:

JS Code:

function toggleMe(id){
	var e = document.getElementById(id);
	if (toggleMe.last && toggleMe.last !== e){
		toggleMe.last.style.display = "none";
	}
	toggleMe.last = e;
	// Prüfung exixtiert eine Element mit dieser ID?
	if (e){
		// Umschaltung
		if (e.style.display === "none"){
			e.style.display = "block"
		}
		else {
			e.style.display = "none"
		}
	}
}

What is this? - It's realy easy. If you create a div and put the style "display: none" in it then you can create a link to show / hide the created Div if you click the Link.
Here's the html for a link which hides a div with id "hideMe"

HTML Link:
<a type="button" class="btn btn-success" onClick="toggleMe('hideMe')">3 Tages Vorhersage</a>

HTML Div:
<div id="hideMe" style="display: none;">
	Your Content here
</div>

I hope this can help you in some cases
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Antworten in Thema: Display / Hide Div with Javascript by click

Display / Hide Div with Javascript by click davidduckwitz 3 Jahre 9 Monate her
Ladezeit der Seite: 0.100 Sekunden