Automatically close all the other
tags after opening a specific
tag

前端 未结 6 519
日久生厌
日久生厌 2021-02-06 01:08

Here is my code.



        
6条回答
  •  一个人的身影
    2021-02-06 01:35

    Yet another answer for those who don't want to use obsolete jQuery and those who loves functional javascript

    [...document.getElementsByTagName("details")].forEach( (D,_,A) =>
      D.addEventListener("toggle", E =>
        D.open && A.forEach(d =>
          d!=E.target && (d.open=false)
        )
      )
    )
    1Demo 1
    2Demo 2
    3Demo 3

提交回复
热议问题