So the issue that you are having is that when you use a jQuery selector, you create a unique jQuery object (or collection of objects, if there is more than one), that contains a bunch of information about the matching element, including a reference to the DOM element itself (the first bit of information, referenceable by $("#someElement")[0]
Since these objects are unique, while they may contain identical information about the returned element, the objects themselves are not equal. So, for:
var bodyRef1 = $("body");
var bodyRef2 = $("body");
var bodyRef3 = $("body");
You will find that the values contained in the object are all equal:
bodyRef1[0] === bodyRef2[0] === bodyRef3[0]
bodyRef1.context === bodyRef2.context === bodyRef3.context
etc. . . .
The objects themselves are not
bodyRef1 !== bodyRef2 !== bodyRef3
In your case, unless there is a specific reason why you need to have the elements selected in a jQuery format, you might actually be better off simply doing a native JavaScript selection, and remove the extra layer of complexity:
var myDOMS = new Array();
myDOMS.push(document.getElementById("myDiv"));
var element_to_remove = document.getElementById("myDiv");
var index = $.inArray(element_to_remove, myDOMS);
if (index > -1) {
myDOMS.splice(index, 1);
}
This works because the native JS selection returns only a reference to the DOM element.
$("#myDiv")but it could be$(".myDiv")..