0

I have a list. And am trying to get the context of the list when the user clicks the text using prototype. But this code doesn't not alert the message. What is the wrong with the code?

The code can be seen here: www.modernarapca.com/test.php

JavaScript:

$$('ul#myList2 li').each(function(elmt) { 
    elmt.observe('click', function(ev) {
        var  tab;
        tab = elmt.down('a').readAttribute('href');
        alert("entered");    
    });  
}); 

Markup:

<ul id="myList2">
    <li>
     <a href="javascript:;" class="" >text1</a>
    </li>
    <li>
     <a href="javascript:;" class="" >text2</a>
    </li>
    <li>
     <a href="javascript:;" class="" >text3</a>
    </li>
</ul>
4

1 回答 1

-1

或者也许这个...

$('document').ready(function() {
    $('#myList2 li').on('click', function(el) {
        console.log(el.target);
        var cont = $(el.target).html();
        alert(cont);
    });
});
于 2013-03-15T08:29:59.670 回答