in Advanced 

Question preview

HomeQuestion preview:
Log in

Find the clicked anchor

How can i find which element was clicked in a structure like this:
<ul id="menu">
    <li><a>link 1</a></li>
    <li><a>link 2</a></li>
    <li><a>link 3</a></li>
</ul>
Do you know someone who could answer? Ask him for help
Answers: 1
Sort by: date rating
image rostislav
15:26/09.01.2008
1.8 from possible 5 with 5 votes
Try the following one:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            function findClicked(event) {
                var target = event.target || window.event.srcElement;
                if (target.tagName == 'A') {
                    alert(target.innerHTML + ' is clicked.');
                }
            }           
        </script>
    </head>
    <body>
        <ul id="menu" onclick="findClicked(event)">
            <li><a href="#">link 1</a></li>
            <li><a href="#">link 2</a></li>
            <li><a href="#">link 3</a></li>
        </ul>      
    </body>
</html>
Vote:
Please vote! Your opinion matters!
If you haven't found what you've looking for, post a question
Ask question
| Home | Hall of fame | Registration | Log in | Terms of service | Privacy policy | Help | Contacts | RSS |