JavaScript add class depending on current URL

前端 未结 2 1212
故里飘歌
故里飘歌 2020-12-17 05:01

For my website navigation I need to add the class \'active\' to the li element depending on if it matches the current URL.

Nav HTML:

2条回答
  •  不思量自难忘°
    2020-12-17 05:27

    If you want to use "pure" ("vanilla") JavaScript, use the following code(assuming that

提交回复
热议问题