The first 4-element onClick element works, but each after that does not work - in FF 3.6 and Chrome

Sorry for the confusing name, but this is the best I can describe ... So, I have a TD element, and when it double-clicked jQuery, the ajax function returns ul from a PHP script.

New code (sorry for that):

Here is the jQuery Ajax code:

    //Create PU:
    $('#DD_'+IDNum).append('<div class="popUp" id="PU_'+IDNum+'"></div>');

    //ajax:
    $.ajaxSetup ({
        cache: false
    });
    var ajax_load = '<img class="loading" id="LG_'+IDNum+'" src="../images/loading.gif" />';
    if(key==0)
        var term = '';
    else
        var term = $('#TC_'+IDNum).val();
    //load() functions
    var loadUrl = "./ddGet.php?Ele="+element+"&Client="+ClientID+"&vendorName="+vendorName+"&id="+IDNum+"&term="+term;
    $('#PU_'+IDNum+'').html(ajax_load).load(loadUrl);

Here is a PHP snippet:

$result = mysql_query($query) or die(mysql_error());
$response= '<ul id="DD_UL">';
$resultArray = array();
$class = "li-odd";
$i = 1;
while($row = mysql_fetch_array($result))
{
    if(!in_array($row[0], $resultArray)){
    $resultArray[]=$row[0];
    if(isset($row[1]))
        $roW1 = ' - '.$row[1];
    else
        $roW1 = '';
    $response .= "\n".'<li id="LI_'.$id.'_'.$i.'" class="'.$class.'">'.$row[0].$roW1.'</li>';
    //selectLI(\'LI_'.$id.'_'.$i.'\')
    if($class == "li-odd")
        $class = "li-even";
    else
        $class = "li-odd";
    $i++;
    }
}
$response .= '</ul>';
echo $response;

Here is the response text:

<ul id="DD_UL">
<li id="LI_1_1_1" class="li-odd">E02_02</li>
<li id="LI_1_1_2" class="li-even">E02_03</li>
<li id="LI_1_1_3" class="li-odd">E02_04</li>
<li id="LI_1_1_4" class="li-even">E02_05</li>
<li id="LI_1_1_5" class="li-odd">E02_06</li>
<li id="LI_1_1_6" class="li-even">E02_07</li>
<li id="LI_1_1_7" class="li-odd">E02_08</li>
<li id="LI_1_1_8" class="li-even">E02_09</li>
<li id="LI_1_1_9" class="li-odd">E02_10</li>
<li id="LI_1_1_10" class="li-even">E02_11</li>
<li id="LI_1_1_11" class="li-odd">E02_13</li>
<li id="LI_1_1_12" class="li-even">E02_14</li>
<li id="LI_1_1_13" class="li-odd">E02_20</li>
</ul>

And finally, there will be a new function called after UL that assigns .live:

function selectLI(){
        $('#DD_UL').live('click',function(e){
        var id = e.target
        id = $(id).attr('id');
        var IDNum = id.substr(3);
        IDNum = IDNum.substring(0,IDNum.lastIndexOf("_"));
        var newVal = $('#'+id).html();
        if(newVal.indexOf(" - ")>0)
            newVal = newVal.substring(0, newVal.indexOf(" - "));
        $('#TC_'+IDNum).val(newVal);
        });  
    }

Not so easy, huh? At first, I noticed that in Chrome onclick will only work if it looks like one of the first 4 or so. After the first four (or so) nothing will happen. Then I noticed that FF 3.6 does the same. I am checking IE (although the page is not meant to run in IE) and it worked. Finally, FF 4 works great.

" ", 4,5,6,7... , . , , , .

, .

+3
2

:

onClick . ID UL (, list).

jQuery:

$('#list').live('click', function(e) {
    var anchor = e.target;
    // do stuff with your anchor
});

: http://jsfiddle.net/7Lqtn/

+2

Hm.. , ( Firefox 3.6, ).

JSFiddle: http://jsfiddle.net/rQYFW/

Firefox 4, Chrome 11, IE 9.

0

All Articles