Answer the question
In order to leave comments, you need to log in
Assign a class to an element in a menu based on the class of the active menu?
Good afternoon!
There was a problem, I figured out how to solve it, but I don’t know how.
Site on modx, accordion menu (bootstrap collapse), it is necessary that the active menu item be open.
I came up with a solution like:
If there is a class "myclass" (this is the class of the active item), then add the class "IN" to a certain div with a class on the site, in my case the closed item has the class "collapse", and the open one "collapse in"
This is real ? Are there any solutions of this kind in JS?
Answer the question
In order to leave comments, you need to log in
There are 2 possible solutions, all boil down to adding a class. You can add it on the server when generating the html menu or in js.
In js, the problem is that you need to take the current url and compare it with the href of the link, but they do not always match. For example, hash tags or parameters can be added, and this is another line. Accordingly, the script should provide for this.
It is often more convenient to do this on the server, but in the case of MODX this is not always the case.
There are a lot of js scripts:
https://yandex.ua/search/?rdrnd=701635&win=200&tex...
choose, probably not all are adequate
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question