There is a method where I want to find an element by class in a particular html.
someMethod(html) {
$('.some-class', html).click(function(){
...
})
}
And run it like this
someMethod(html)
Provided that html does exist(not null).
I also want to use the same method above to find for the same element through the DOM of the current page. So html
in the method would be null.
Will it work if I run it like this?
someMethod()
CodePudding user response:
As far as i can see in the source code of the selector it just defaults back to document
if an invalid context (e.g. null, false, undefined, ...) is given.
From the JQuery Source Code (https://github.com/jquery/jquery/blob/main/src/selector.js)
// nodeType defaults to 9, since context defaults to document
nodeType = context ? context.nodeType : 9;