views:

24

answers:

2

Why isn't this snippet showing "YES" in the div id = debug after

  1. each item in id=box is clicked and placed in id=que. (assigned class click2Remove)
  2. then clicked again in que?

?


<script>
var idcurrent = 0;
$(document).ready(function() {
    $(".click2Select").click(function() {
        idcurrent = this.id;

        $("#" + idcurrent).attr("class", "removed");
        var s = '<a href="" onclick="return false" id="' + idcurrent + '" class="click2Remove">' + $("#" + idcurrent).html() + '</a>';
        $("#que").append(s);
        $("#debug").html("selected and in que: "+idcurrent);
    });
});
$("#que").delegate("click2Remove", "click", function() {
    $("#debug").html("YES");

});​
</script>

<div id="box">
    <li><a class="click2Select" onclick="return false" href="#" id="1">1</a></li>
    <li><a class="click2Select" onclick="return false" href="#" id="2">2</a></li>
    <li><a class="click2Select" onclick="return false" href="#" id="3">3</a></li>    
</div>

<div id="que">
</div>

<div id="debug">
</div>​


http://jsfiddle.net/HWD9J/

A: 

Your .delegate() selector needs a tweak, the class selector needs a ., like this:

$("#que").delegate(".click2Remove", "click", function() {

Here's the version with a ., working :)

Nick Craver
yes thanks - just realized that as i was editing to format for stackoverflow.. (doh!!)
ina
A: 

Ack, forgot the . in the delegate... mea culpa!!

ina