You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{$}from'dollarDom'constdomElement=document.getElementById('#someElementID');console.log(domElement);// This prints the dom element$(domElement).on('click',function(){alert(this.innerHTML)});// throws error
The above code throws the error:
Issue:
the $ method is not checking the type of the selector -- so ideally, it should check if the selector is a string or a dom node before calling the .trim() / or other actions on the selector.
The text was updated successfully, but these errors were encountered:
Sometimes, there are chances that people pass the entire DOM element as the selector. ( Mostly anyone who comes from the jQuery background would've done that ).
Ideally, we need to handle that situation gracefully, instead of the code throwing the unhandled exception.
Assume the following code:
The above code throws the error:
Issue:
the
$
method is not checking the type of the selector -- so ideally, it should check if the selector is a string or a dom node before calling the.trim()
/ or other actions on the selector.The text was updated successfully, but these errors were encountered: