Bug Tracker

Opened 16 years ago

Closed 16 years ago

#1034 closed bug (duplicate)

Problem with .bind () method

Reported by: CobaltWave Owned by:
Priority: major Milestone: 1.1.3
Component: event Version: 1.1.2
Keywords: bind, event handler, pass data object Cc:
Blocked by: Blocking:

Description

Hello,

The .bind () method is not behaving like I would expect it to. I have two lists in HTML:

<ol id="greenList">

<li>Notepads</li> <li>Books</li> <li>Pens</li> <li>Pencils</li> <li>Binders</li>

</ol>

and

<ol id="blueList"> </ol>

I have the following event handler, that moves clicked elements to the other list:

function moveItem (e) {

var targetList = "ol#" + e.data.target; $(e.target).clone ().appendTo (targetList); $(e.target).remove ();

}

I would like to bind the event handler to each <ol> element like so:

$("ol#greenList").bind ("click", {target: "blueList"}, moveItem); $("ol#blueList").bind ("click", {target: "greenList"}, moveItem);

However this doesn't work. Once the .bind () for blueList is performed, the e.data.target for the event handler in the greenList is "greenList" and it should have remained "blueList".

I had to rewrite my event handler like so:

function moveItem (e) {

var targetList = "ol#" + e.data [$(this).attr("id")]; $(e.target).clone ().appendTo (targetList); $(e.target).remove ();

}

and bind in this fashion for the code to work:

$("ol#greenList").bind ("click", {greenList: "blueList", blueList: "greenList"}, moveItem); $("ol#blueList").bind ("click", {greenList: "blueList", blueList: "greenList"}, moveItem);

This doesn't seem right to me. Is there a bug with passing a "data" object to the bind method?

Best regards, JEK

Change History (1)

comment:1 Changed 16 years ago by john

Resolution: duplicate
Status: newclosed

This is a duplicate of bug #935.

Note: See TracTickets for help on using tickets.