amir moradifard
amir moradifard

Reputation: 353

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.

Upvotes: 0

Views: 478

Answers (3)

Anup Khandelwal
Anup Khandelwal

Reputation: 365

Use bind instead of live()

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

Upvotes: 1

EnterJQ
EnterJQ

Reputation: 1014

Make use of live() instead of on() for latest versions

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

Upvotes: 0

bipen
bipen

Reputation: 36541

if you are using jquery 1.9... the live() is removed ..so use on

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

or else if your <li> is not added dynamically thn you can call directly.

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

Upvotes: 0

Related Questions