After feedback, complete rewrite of the question.
I have the following mark up :
<body>
<h1>Title</h1>
<p>bla</p>
<div>
... <!-- a thousand tags -->
</div>
<div id="do-not-modify-me">
<!-- a hundred tags -->
</div>
</body>
I can access to :
<h1>Title</h1>
<p>bla</p>
<div>
... <!-- a thousand tags -->
</div>
Using :
$('body > *:not(div#do-not-modify-me)');
I do that so I can get all the content of the body except the div with the id "do-not-modify-me".
Now, let's say that I want to build a function that let another programmer to select anything in the body, just like the select with jquery. The other programmer should not modify div#do-not-modify-me, but he should not have to care about it neither.
$('body > *:not(div#do-not-modify-me)')
will be called a lot of time, so we will cache it.
The idea is :
// TEST CODE
windows.new_body = $('body > *:not(div#do-not-modify-me)');
function select(selector) {
return $(selector, windows.new_body);
}
So the other programmer should be able to do :
// TEST RESULT CODE
select("p").css("color", "red");
It would color in red all the <p>
in the body, but not the ones contained in div#do-not-modify-me.
The TEST CODE does not work, because currently, it applys css() on the children of the result of the context, not the result it self.
E.G :
select("p").css("color", "red");
Behaves like :
$('body > * p :not(div#do-not-modify-me)').css("color", "red");
While the desired result would be :
$('body > p :not(div#do-not-modify-me)').css("color", "red");
Note that :
$('body > * :not(div#do-not-modify-me)').parent().css("color", "red");
Does not work because the <p>
div#do-not-modify-me turn into red.
How would you obtain the result in TEST RESULT CODE ? You can modify any part of the code.