Is it possible in some way to reconfigure jQueryfor search only in the subtree of the specified element?
I need to do something like this:
var lockToSubtree = function (jq) {
return reconfiguredJQuery;
},
myJQuery = lockToSubtree(jQuery, '.my-namespace');
So, I have my own jQuery instance that searches for elements only inside '.my-namespace'.
To illustrate my needs, an HTML example is provided:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="divOne" class="someClass"></div>
<div class="my-namespace">
<div id="divTwo" class="someClass"></div>
</div>
</body>
</html>
Therefore, I can use later in my code:
var $el = myJQuery('.someClass');
And he will search .someClassonly in the subtree .my-namespace. Therefore, he will return only div#divTwoand div#divOnewill be skipped, because he is not under the subtree .my-namespace.
, , .my-namespace jQuery .closest() .., . :
var $myJQuery = lockToSubtree(jQuery, '.my-namespace'),
$el = myJQuery('.someClass'); // $el is the
$el.closest('body'); // finds nothing, because body is not located under .my-namespace
UPDATE:
@Keith , , , jQuery .closest, . , , .
, jQuery, , jQuery ( , jQuery.fn ..).
. ββ , HTML . - JavaScript jQuery. , , jQuery, DOM, jQuery.
, , :
(function (jQuery) {
}());