skip to Main Content

(Minimal javascript experience)

Source pasted into Chrome JavaScript Console:

 (function doesIconExist() {
    var xPath = '//*[@id="downloadActivityIcon"]'
    var nodes = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null);
    return (nodes.iterateNext() ? ‘present’ : ‘absent’);
}
 )();

The console reports the subject error message and links to this:
image showing location of error
–which I post as an image to show the squiggly red line.

I tried converting the ternary conditional to an if statement:

if (nodes.iterateNext())
    return 'present' ;
return 'absent' ;

but it generates the same error with the squiggly red line starting in the first return under the first ' and extending through the semicolon.

2

Answers


  1. Chosen as BEST ANSWER

    As spotted by @Pointy, the single quotes in the return statement were of the slanted variety used in word processing. I have no idea how they became so, but correcting them to proper ' single quotes solves the problem.


  2. You can just replace the ` by ' or by "and your code could look like this :

    (function doesIconExist() {
        var xPath = '//*[@id="downloadActivityIcon"]'
        var nodes = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null);
        return (nodes.iterateNext() ? 'present' : 'absent');
    }
     )();
    

    I personaly tried in my console and it’s working.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search