I have a plugin, jKey, and people kept reporting IE bugs that it didnt work. The bug isn’t with my script, or jQuery, but rather IE doesn’t support window keypresses. I want to “auto-correct” this by checking if the $(window) was selected (which i did below by check, if “this” has a parentNode) and if it was i want to switch this to document.
I’m having no luck tho. I keep getting:
Uncaught ReferenceError: Invalid left-hand side in assignment
I’ve tried:
if($(this)[0].parentNode == undefined){
$(this) = $(document);
}
And:
if($(this)[0].parentNode == undefined){
this = document;
}
Any ideas? Also, if you have a better way of checking for the window please let me know!
$is a function.$(this)is a function invocation. You cannot assign a value to a function invocation.thisnever directly assignable.Are you really jQuery-ifying
thisand then immediately unwrapping it?In the plugin, alias
thisto a keyword that you can assign. A frequent choice isself:Now you actually can change the “scope:”
Oh, right, you’re talking about a jQuery plugin.
thisis probably already a jQuery object, in which casethis.parentNodewould always be a falsy value. You can either unwrap it:or use