I’m very new in scripting with js. My question is, how can i set an onclick at an h1, which set the display to none at another div?
Here my code:
var iter;
function toggleGroups()
{
function getAllGroups()
{
titlebars = document.getElementsByClassName('titlebar_js');
groupfields = document.getElementsByClassName('inner_groups_gether');
for(i = 0; i < titlebars.length;i++)
{
tb = titlebars[i];
iter = i;
tb.onclick = function()
{
alert(iter);
groupfields[iter].style.display = 'none';
}
}
}
getAllGroups();
}
window.onload = function()
{
toggleGroups(); // Aufruf der Funktion
}
It doesn’t work.
Hey, the other guy is right, jQuery is great for solving this very quickly. Example:
Here you are telling the browser to grab any h1 tag and make the divs with class “toBeHidden” to disappear.
You can learn bout jQuery here. It is worth it for sure. I rarely use pure javascript again after having started with jQuery.