Repeating a jQuery select event for the same index

In jQuery (or in browsers, I'm not sure anymore) there is a neat little function that, when you use the keyboard to navigate the select element, ensures that the jQuery "change" event does not reload when pressed, enter it several times.

This is all good and good, but I'm working on a list with several choices where the selected items are removed from the list and added below. This leads to the fact that you cannot select an element with the same index as the previous element that you selected (using only the keyboard), because they are considered identical.

In IE, I can solve the problem by dropping the comparative data with the following code at the end of the change event:

jQuery.data(this, "_change_data", null); 

I do not know why it only works in IE. Is there a way to re-fetch for the same index for each change event trigger?

Solution: A simple workaround was to simply disable the selected values, rather than remove them from the list.

+4
source share
1 answer

I have not tested it, but I think this may help:

event.preventDefault ()

I saw that it was used for mouse clicks - but I think it should work for all events. However, I think that it relies on the fact that browsers correctly implement the behavior of their events, so there may be problems with the browser.

0
source

Source: https://habr.com/ru/post/1336792/


All Articles