lundi 11 juillet 2016

How can I create an expression that evaluates whether or not a parent div's descendants are active?

Imagine I have a div with a few descendants/children as such:

<div id="parent" tabindex="0">
  <h1 tabindex="0"> my Header </h1>
  <p tabindex="0"> some text </p>
  <ul tabindex="0">
     <li tabindex="0"> item 1 </li>
     <li tabindex="0"> item 2 </li>
     <li tabindex="0"> item 3 </li>
  </ul>
</div>

How can I create an expression that checks whether or not a child of the 'parent' div is active/has focus? I'd like to perform some action (ex: console log) if the statement evaluates to true.

I'd imagine it's go something like:

if( document.activeelement === <descendant of 'parent' div>) {
     console.log("descendant is active"); 
  }

Aucun commentaire:

Enregistrer un commentaire