Skip to content Skip to sidebar Skip to footer

Jquery ".on( 'click' ,....)" Does Not Work With Let Variable Declaration. But Works Var

Is this a jquery bug? I have a simple click event. When I use LET to declare some variables with image links, the click event stops working on my ipad (chrome). When I switch to LE

Solution 1:

The let variables is only available in it's block scope. In your case, you can't use the three let variables if they are outside the jQuery block.

Here's a link that explain well the difference between var, let and const. https://www.sitepoint.com/preparing-ecmascript-6-let-const/

Solution 2:

I don't see that you even used the defined variables imageLink*.

It's possible that your browser doesn't support let statements. According to Can I Use? it's fully supported by default in Chrome 49 and above.

If it's not supported it'll cause syntax error preventing JavaScript from further execution. That means, your click event will never be set!

Check which version of Chrome you're running on your iPad. If it's below 49, that's your answer.

However, if the version is between 41 and 48 it's still possible to use let, but you need to be in strict mode. Simply, it requires you to put 'use strict'; at the beginning of your JavaScript code. ;-)

Post a Comment for "Jquery ".on( 'click' ,....)" Does Not Work With Let Variable Declaration. But Works Var"