I want to apply one and the same function multiple times on a page, each time to elements with their own ID (to show and hide elements). When I apply the function without specifying IDs, all elements all over the document would change. So do I have to specify the function multiple times in the Javascript file, each with its own ID, or is it possible to get the ID somehow at runtime?
HTML
<button onclick="switchIt_stahlherstellung">switch</button>
<div id="stahlherstellung">
show/hide stuff
</div>
<button onclick="switchIt_produkte">switch</button>
<div id="produkte">
show/hide stuff
</div>
and so on.
Javascript
function switchIt_stahlherstellung() {
if (document.getElementById('stahlherstellung')) {
if (document.getElementById('stahlherstellung').style.display == 'none') {
document.getElementById('stahlherstellung').style.display = 'block';
}
else {
document.getElementById('stahlherstellung').style.display = 'none';
}
}
}
function switchIt_produkte() {
if (document.getElementById('produkte')) {
if (document.getElementById('produkte').style.display == 'none') {
document.getElementById('produkte').style.display = 'block';
}
else {
document.getElementById('produkte').style.display = 'none';
}
}
}
</button>end tag ? this can be a problem