Bug Tracker

Ticket #1034 (closed bug: duplicate)

Opened 2 years ago

Last modified 2 years ago

Problem with .bind () method

Reported by: CobaltWave Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.1.3 Component: event
Version: 1.1.2 Keywords: bind, event handler, pass data object
Cc: Needs:

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

Change History

Changed 2 years ago by john

  • status changed from new to closed
  • resolution set to duplicate

This is a duplicate of bug #935.

Note: See TracTickets for help on using tickets.