V
V
Vladimir Novitsky2015-11-21 04:34:10
JavaScript
Vladimir Novitsky, 2015-11-21 04:34:10

How to assign the same keyboard shortcut to two elements?

There is this code:

e2_ctrl_navi = function(event) {
  if (window.event) event = window.event
  var target = (event.srcElement || event.target).tagName;
  if (/textarea|input/i.test(target)) return

  if (
    (document.e2.mac && event.altKey) || (!document.e2.mac && event.ctrlKey)
  ) {
    var link = null
    if (37 == event.keyCode) link = document.getElementById('link-prev')
    if (39 == event.keyCode) link = document.getElementById('link-next')
    if (38 == event.keyCode) link = document.getElementById('link-later')
    if (40 == event.keyCode) link = document.getElementById('link-earlier')
    if (link && link.href) {
      location.href = link.href
      if (window.event) window.event.returnValue = false
      if (event.preventDefault) event.preventDefault()
    }
  }
}

All four idhave different keyboard shortcuts assigned.
And I need something like this:
if (37 == event.keyCode) link = document.getElementById('link-prev')
if (39 == event.keyCode) link = document.getElementById('link-next')
if (39 == event.keyCode) link = document.getElementById('link-later')
if (37 == event.keyCode) link = document.getElementById('link-earlier')

For #link-prevand #link-earliermust be the same key combination. Likewise for #link-nextand #link-later.
But it doesn't work like this.

PS At the same time, only one of the pairs occurs on the page, so there should be no conflicts.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question