Your code you have should work: http://jsfiddle.net/GxCCb/
It is important to note that the elements you are trying to attach an event handler must exist when the code is evaluated. If it is added later, you should use on() (v1.7 +) or delegate() (<1.7), which is used to delegate events and allows you to refer to elements if they are added later.
Using on () :
$("#resultsBox").on('click', 'li', function (event) { alert(this.innerHTML); });
Demo: http://jsfiddle.net/7Lz2Y/
Using delegate () :
$("#resultsBox").delegate('li', 'click', function (event) { alert(this.innerHTML); });
Demo: http://jsfiddle.net/XwYs5/
However, there are many other methods for binding an event handler for previously existing elements:
$("#resultsBox").find('li').click(function (event) { alert(this.innerHTML); });
Demo: http://jsfiddle.net/74Q7p/
$("#resultsBox ul > li").click(function (event) { alert(this.innerHTML); });
Demo: http://jsfiddle.net/a28U5/
Robb
source share