auto-click event on key events?
Why does an additional click event fire upon any key event? This has been observed in FF45
by Laberwurschd
HTML
<h1>My Quiz</h1>
<p>Here could be a quiz...</p>
<form id="quiz" action=""></form>
CSS
#quiz ul {
list-style: none;
margin: 0;
padding: 0;
}
#quiz li {
margin: 0;
padding: 0;
}
#quiz label {
display: block;
background: #8d8;
border: 2px solid #8d8;
border-radius: 0.2em;
margin: 0.1em 0;
padding: 1em 2em;
text-align: center;
width: 10em;
}
#quiz label:hover {
background-color: #dfd;
}
#quiz input:checked ~ label {
background-color: #f88;
border-color: #faa;
}
#quiz input {
left: -9999px;
position: absolute;
}
#quiz button:not(.startBtn) {
display: none;
}
#quiz button,
#quiz label {
cursor: pointer;
}
JavaScript
var myQuiz = {
container: null,
// helper function
createElement: function(o) {
var el, p;
if (o && (o.tag || o.tagName)) {
el = document.createElement(o.tag || o.tagName);
if (o.text || o.txt) {
el.appendChild(
document.createTextNode(o.text || o.txt)
);
}
for (p in o) {
if (!p.match(/^t(e)?xt|tag(name)?$/i)) {
el[p] = o[p];
}
}
}
return el;
},
// user interface for a quiz question
createOptions: function() {
var t = this,
options = [],
ul = document.createElement("ul");
t.emptyContainer();
t.intoContainer(t.createElement({
tag: "h1",
text: t.currentQuestion.question
}));
t.intoContainer(ul);
// create options
options.push(t.currentQuestion.solution);
t.currentQuestion.falses.forEach(function(s) {
options.push(s);
});
t.shuffleArray(options);
options.forEach(function(s, i) {
var li = document.createElement("li"),
label = t.createElement({
htmlFor: "a" + t.questions.length + "_" + i,
tag: "label",
text: s
}),
radio = t.createElement({
id: "a" + t.questions.length + "_" + i,
name: "answer",
tag: "input",
type: "radio",
value: s
});
ul.appendChild(li);
li.appendChild(radio);
li.appendChild(label);
// preselect first option
if (i < 1) {
window.setTimeout(
function() {
radio.focus();
radio.checked = true;
},
100
);
}
});
// Hinweis für Tastatur-User
t.intoContainer(t.createElement({
tag: "button",
text: "confirm choice",
type: "submit"
}));
},
currentQuestion: null,
// data could be filled from an external source (JSON)
data: [{
...