0

How does this data.target == this work?

jquery example

.mouseup(function(data, handler)
        {
           if(data.target == this)
           {
              // some code
           }
        })

Does this compare the objects by comparing each of their respective properties?

I need this check because I want the mouseup only on the parent div and on one child.

if (data.target == this || * if this has className XXX  * ) {
   // some code
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Peter
  • 11,413
  • 31
  • 100
  • 152

2 Answers2

3

if (data.target == this) evaluates to true if this refers to the same object in memory as data.target.

The == operator does not compare member values. See Object comparison in JavaScript.

Community
  • 1
  • 1
Saul
  • 17,973
  • 8
  • 64
  • 88
0

Since you are using JQuery you don't need to worry about the comparison. Just use .live to bind the mouseup to the two elements of interest.

$(myDiv).live('mouseup',myFunction());
$(myChildElement).live('mouseup',myFunction());

You'll need to write code to handle the situation where the mousedown was not on target, e.g. the user clicked down somewhere else and dragged the mouse over your target before releasing.

Darin
  • 2,071
  • 2
  • 17
  • 14