Get Clicked <li> from <ul onclick>
问题 As a relative beginner with JS, I am struggling to try and find a solution to this. I need to find out which line of an unordered list was clicked <ul onclick="alert(this.clicked.line.id);"> <li id=l1>Line 1</li> <li id=l2>Line 2</li> <li id=l3>Line 3</li> </ul> I don't really want to add a onclick event to each individual line, I'm sure there must be a way ?? 回答1: You can use event.target for this: JS: // IE does not know about the target attribute. It looks for srcElement // This function