Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:15+00:00 2026-06-09T18:31:15+00:00

I know how to do this in jQuery, but how to do it in

  • 0

I know how to do this in jQuery, but how to do it in Javascript?

    if ((evt.which == arrLeftKey || evt.keyCode == arrLeftKey) && document.getElementById(TopMenuID).getElementsByTagName('a') === document.activeElement) {
                alert("LEFT");
} 

The above if statement isn’t working, and I’m not really sure why. Nothing is being alerted. I have a nav bar called TopMenuID and if one of the a tags inside of it have focus, I want to alert LEFT when the left key is pressed. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:31:16+00:00Added an answer on June 9, 2026 at 6:31 pm

    getElementsByTagName('a') returns an array, but you are comparing it to activeElement thus the two will NEVER be equal.

    If you want to know if the activeElement is in your menu, then you can look up the parent chain of the activeElement and just see if you run into the TopMenuID element.

    function doesContain(item, parent) {
        var obj = item.parentNode;
        while (obj && obj !== document.documentElement && obj.nodeType !== 11) {
            if (obj === parent) {
                return(true);
            }
            obj = obj.parentNode;
        }
        return(false);
    }
    
    if ((evt.which == arrLeftKey || evt.keyCode == arrLeftKey) && doesContain(document.activeElement, document.getElementById(TopMenuID) {
        alert("LEFT");
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how I would achieve this using PHP, but with jQuery / JavaScript
I know this question is quite basic but I am new to JQuery and
I'm using this jQuery inline datePicker plugin sample but I don't know how to
Do browser vendors optimize against jQuery? I know this sounds absurd anti-standard, but I
I know it's possible with jQuery, but I'm having some serious troubles with this
I know there exists a command like jQuery.noConflict. But for this it first registers
I don't know if anyone ELSE has noticed this, but I noticed the jQuery
I know this sounds pretty trivial, but I'm new to jQuery... I use this
I know this is quite easy to do in jQuery, but I am trying
I know Suckerfish does this very well, but I don't like the javascript in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.