How to implement the selection of multiple items by id?

There are several id types:
#best-id-N
where N is the number. From 1 to 20, for example.

All of them default to the CSS class "best class".

And you must do the following:
If the pointer is over a 13th element, then all previous (1 to 13) elements need to add new CSS class "best-class-for-item".

Did you add this class to the element that the cursor is on, and here's how to make the items to him - I don't know.

Help, please.
July 9th 19 at 10:32
2 answers
July 9th 19 at 10:34
Solution
July 9th 19 at 10:36
Learn N from this id and use the same N in a loop:
for (var i = 1; i <= N; i++) { ... }
And how do you know the number? He is in the event e does not appear. Only the id entirely. Is to parse the string of the regular season? - alfonzo.Zeml commented on July 9th 19 at 10:39
Or maybe place the number in data-id and then get its ID, and then cycle? - alfonzo.Zeml commented on July 9th 19 at 10:42
: with the regular season will be easier - kevon_Torphy commented on July 9th 19 at 10:45
: can type additional type attribute data-best-id="N" and use it to find out - berneice.Abshi commented on July 9th 19 at 10:48
: what I think I wrote above? :) - alfonzo.Zeml commented on July 9th 19 at 10:51
: when I wrote the comment was not displayed)) - berneice.Abshi commented on July 9th 19 at 10:54
: okay :) - alfonzo.Zeml commented on July 9th 19 at 10:57

Find more questions by tags jQuery