In another question answered here I found the following JavaScript code:
function _dom_trackActiveElement(evt) {
if (evt && evt.target) {
document.activeElement = evt.target == document ? null : evt.target;
}
}
But this syntax is unknown to me, could someone explain exactly what
document.activeElement = evt.target == document ? null : evt.target;
does?
? :is the conditional operator, sometimes called the “ternary operator”. As an example,a ? b : cwill returnbifaistrue, andcotherwise.Your code will assign
nulltodocument.activeElementifevt.target == document. Otherwise,evt.targetwill be assigned.