Gandalf
Gandalf

Reputation: 13683

Using on instead of live to hide a div with a specific id on link click

I am trying to hide a div with an id #op-four using on instead of live

$("#one").on("click", function() {
    $("#op-four").hide();
});​

fiddle http://jsfiddle.net/ythSA/ but it wont work

Upvotes: 1

Views: 523

Answers (2)

Roko C. Buljan
Roko C. Buljan

Reputation: 206078

Try with:

$('.links-holder').on('click','#one',function() {
   $("#op-four").hide();
});

This use of the .on method replaces the now deprecated .live().

$( document /or/ 'parent_el').on( 'some_event' , 'delegated_element', function(){

Read more: http://api.jquery.com/on

Upvotes: 1

James Montagne
James Montagne

Reputation: 78650

You've placed your code outside of your ready handler. Move it inside and it works fine.

http://jsfiddle.net/ythSA/2/

You were trying to attach a handler to #one before it actually existed.

Upvotes: 1

Related Questions