Is there something like $ ('a # link_id'). Activate () in jQuery?

When I bind a function to a link with $('a#link_id').click() , and then I click the link, it launches the function and anything else, but when I β€œactivate” the button in a different way (that is, I focus on the tab, and then click barpace) it just doesn't work.

The same thing happens with $('select#dropbox_id').change() : it works when I change it with the mouse, but not with the direction arrows. Is there a way to achieve this without having to manually redraw using $.keyup() ? I don’t know, maybe I just missed the event.

+4
source share
2 answers

You do not need any events.

For the click event, this happens when you click an element with the mouse or with a space. If the click event does not fire when using a space, you may have an error somewhere else.

When you change the drop-down list, then and only then does the change event fire. When you use the arrow key to change the selected value of the drop-down list, this value is not selected immediately, only when the focus of the control is lost, this destination is assigned its selected control value, and as a result, the event changes.

If you want to use the shooting mechanism using the arrow keys, you will need to use the keyup / keydown event, there is no other way (as far as I know). In addition, you can detect a key that has been pressed to determine if it is one of the direction arrows that is pressed.

If you still need help, you can include the code in your question.

Hope this helps.

0
source

I think you are missing the focus or focusin . There is no native event in select elements that fires if, for example, you scroll down the list down the keyboard. focus and focusin fires when element receives focus.

You cannot bind this type of event to options , at least not to crossbrowser. Therefore, if you really want to catch this, you need to bind the keydown or keyup to the parent select element.

0
source

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


All Articles