Skip to content

Instantly share code, notes, and snippets.

@varmais
Created April 2, 2015 08:37
Show Gist options
  • Save varmais/2a23eb6c5667cb73957d to your computer and use it in GitHub Desktop.
Save varmais/2a23eb6c5667cb73957d to your computer and use it in GitHub Desktop.
(function() {
var showIndex = 0;
var titles = document.querySelectorAll('.kysymys');
var questions = document.querySelectorAll('.kysymys + p');
var submit = document.querySelectorAll('button[type="submit"]')[0];
function hideElement (element) {
if (!element) {
return;
}
element.style.display = 'none';
}
function showElement (element) {
if (!element) {
return;
}
element.style.display = '';
}
hideElement(submit);
for (var i = 0; i < titles.length; i++) {
if (i != showIndex)
hideElement(titles[i]);
}
for (var i = 0; i < questions.length; i++) {
if (i != showIndex)
hideElement(questions[i]);
questions[i].addEventListener('click', function (event) {
if (!event.target && event.target.nodeName !== 'INPUT') {
return;
}
if (event.target.parentElement !== questions[showIndex]) {
return;
}
showIndex++;
if (showIndex === titles.length) {
showElement(submit);
} else {
showElement(titles[showIndex]);
showElement(questions[showIndex]);
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment