-5

Referencing this straightforward conversation: Is there an "exists" function for jQuery?

The following code is seeing a zero but still evaluating to 'true' for the first case.

Here is the console result:

Found listView: 0 / 14

The code is in a dialog window...so perhaps it might see the element on the underlying page. But the zero in the log says otherwise...

Really frustrating edge case (or I've just lost my mind). Help appreciated.

if (('#listViewMenu').length) {   //  We are on taskpane list view
        console.log('Found listView: ' + $('#listViewMenu').length + ' / ' + ('#tableViewMenu').length);
        addList();      //hardcoded to list view only - auto load if there is an existing choice for Group
      }
      if (('#tableViewMenu').length) {    //  We are in dialog window table view
        addTable();
      }
11teenth
  • 1,853
  • 1
  • 15
  • 28
  • 6
    you're missing a `$`; `if (('#listViewMenu').length)` should be `if($('#listViewMenu').length)` – Hamms Aug 29 '17 at 23:10
  • 2
    Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) (with HTML) – pyb Aug 29 '17 at 23:10
  • 1
    Here: `('#tableViewMenu').length`, this: `('#tableViewMenu')` is a string, its length is around 20, so this is evaluated as true. You probably meant to call `jQuery`: `$('#tableViewMenu').length` – Al.G. Aug 29 '17 at 23:11

1 Answers1

3

In the first line, have you forgot the $ of jQuery?

if (('#listViewMenu').length)

supposed to be

if ($('#listViewMenu').length)
Rodolfo Marcos
  • 159
  • 1
  • 6
  • Good grief - thank you for the quick answers. Losing my mind here...and was focused on all the other dummies missing the '#'...sheesh. Working now. – 11teenth Aug 29 '17 at 23:28