jQuery on/delegate correct syntax

Posted by KryptoniteDove on Stack Overflow See other posts from Stack Overflow or by KryptoniteDove
Published on 2012-06-02T16:02:37Z Indexed on 2012/06/02 16:40 UTC
Read the original article Hit count: 131

As the jQuery API is currently down, is anyone able to assist me with the below? I am ajax loading an unordered list into the web page and need to be able to attach hover and click events to the list items.

<ul>
  <li class="option">Item 1</li>
  <li class="option">Item 1</li>
  <li class="option">Item 1</li>
</ul>

So far I have tried a few variations of the below jQuery code using .on for version 1.7+

$("ul").on("click", "li .option", function(){
alert($(this).text());
}); 

Can anyone point me in the right direction? I'm aware that .live has been depreciated and that .delegate has been superceeded so really only looking for a solution that will allow me to use .on.

Thanks as always!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery