Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test if two jQuery wrapped DOM elements are the same? [duplicate]

I'm writing a sortable list implementation in jQuery (b/c of the infamous scroll-in-div issue, any new solutions for this?). However, I don't know how to compare the elements (triggered on mousedown/mouseup) after they've been wrapped in jQuery. In prototype, it was always ele.domNode.

This is what I'm trying to accomplish in essence...

<div id="cheese"></div> <div id="burger"></div>  <script>  // Some dom nodes wrapped in jquery var ele1 = $('#cheese'); var ele2 = $('#burger'); var ele3 = $('#burger');  // Is the dom node wrapped in ele1 (#cheese) the same as in ele2 (#burger)? if (ele1 == ele2) {     // Should never be true }  // Is the dom node wrapped in ele2 (#burger) the same as in el32 (#burger)? if (ele2 == ele3) {     // Should always be true }  </script> 
like image 344
John Himmelman Avatar asked Mar 05 '10 20:03

John Himmelman


1 Answers

A jQuery object can be treated as an array of raw DOM elements.

You can compare the raw DOM elements like this:

if(ele2[0] === ele3[0]) 
like image 92
SLaks Avatar answered Oct 05 '22 16:10

SLaks