Skip to main content

Bug Tracker

Side navigation

#1034 closed bug (duplicate)

Opened March 09, 2007 01:58PM UTC

Closed March 15, 2007 04:34PM UTC

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

Attachments (0)
Change History (1)

Changed March 15, 2007 04:34PM UTC by john comment:1

resolution: → duplicate
status: newclosed

This is a duplicate of bug #935.