1

You can see I'm checking help.aria-hidden === "true" But it doesn't work. What's wrong, please help.

Thanks.

function Help() { // Help
    var help = document.getElementById("help_content"),
        overlay = document.getElementById("overlay");

    function closeHelpAndOverlay() {
        help.setAttribute("aria-hidden", "true");
        overlay.setAttribute("aria-hidden", "true");
        textarea.focus();
    }

    if (help.aria-hidden === "true") {
        closeHelpAndOverlay();
    } else {
        help.setAttribute("aria-hidden", "false");
        overlay.setAttribute("aria-hidden", "false");
        textarea.blur();
        document.getElementById("overlay").onclick = function() {
            closeHelpAndOverlay();
        };
        document.onkeydown = function(e) { // esc to close help
            if (e.keyCode === 27 || e.which === 27) {
                closeHelpAndOverlay();
            }
        };

    }

}
drdrb
  • 15
  • 1
  • 4
  • possible duplicate of [How do I reference a javascript object property with a hyphen in it?](http://stackoverflow.com/questions/7122609/how-do-i-reference-a-javascript-object-property-with-a-hyphen-in-it) – Colin Brock Sep 28 '13 at 00:42

2 Answers2

4

You can't use the period syntax for a property that contains a hyphen (as the hyphen is interpreted as the subtraction operator). Use the bracket syntax:

if (help['aria-hidden'] === "true") {
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

Are you expecting that by calling Help(), you'll also be calling closeHelpAndOverlay() immediately upon reaching line 5? It seems you might be thinking that, but it's not the case. You need to explicitly call closeHelpAndOverlay() after you define it.

If that's not the problem you're encountering, please clearly state what you need help on. "It doesn't work" isn't something people can help you with.

musical_coder
  • 3,886
  • 3
  • 15
  • 18