Search code examples
jqueryfunctionclicklive

Jquery add Click event difficulties


I am quite new in Jquery and need help on my following problem:

I am trying to add a Click Function to an existing li elements (sharing same class name) but no success yet.

My html is as follow:

<div class="ol_results" style=" display: inherit; width: 100%; top: 276px; left: 175px;">
<ul>
<li class="myorders">
<span id="Orderid" class="orderDetails">1</span>
<span id="orderDate" class="orderDetails">2012/12/20</span>
<span id="DispatchDate" class="orderDetails">Dispatched</span>
</li>
</ul>
</div>

and my Jquery is:

$('.myorders').live('click', function () { alert("Clicked!") });

What have I missed?

Any helps would be appreciated.


Solution

  • Use bind instead of live()

    $('.myorders').bind('click', function () { 
      alert("Clicked!") 
    });