Ikhlak S.
Ikhlak S.

Reputation: 9024

jquery simple slideToggle not working as expected

This is a simple toggle. The weird thing is that, the event happens when I click anywhere.

This is what my jquery code looks like:

$(document).on('click', $('#create_customer'), function(){
    $('#create_customer_form').slideToggle('slow');
    })

Here is a jsfiddle: https://jsfiddle.net/p8q0uw80/

Upvotes: 0

Views: 31

Answers (3)

Sindhoo Oad
Sindhoo Oad

Reputation: 1194

try this

$(document).ready(function(){
$('#create_customer').click(function(){
    $('#create_customer_form').slideToggle('slow');
    });

} );

and you can simply do

$(document).on('click', '#create_customer', function(){
    $('#create_customer_form').slideToggle('slow');
    })

Upvotes: 0

Bhola Nath Mahto
Bhola Nath Mahto

Reputation: 484

$(document).on('click','#create_customer', function(){
$('#create_customer_form').slideToggle('slow');
});

Upvotes: 1

Manish Jangir
Manish Jangir

Reputation: 5437

Your selector should be something like this:

$(document).on('click', '#create_customer', function(e){
    $('#create_customer_form').slideToggle('slow');
});

Updated your fiddle

https://jsfiddle.net/p8q0uw80/5/

Upvotes: 2

Related Questions