0

I want to use a method in which i will pass a function_name as parameter to another function.

On the other function, the parameter will be treated as a function

here's my code example

<div class="btn_crt_acct" onclick="toggle_object('register_div','slideDown');">
            CREATE AN ACCOUNT
</div>

whch will call a function like this

function toggle_object(obj,fun)
{
    $('#'+obj).fun('slow'); 
    // fun => slideDown
    // so $('#'+obj).fun('slow'); => $('#'+obj).slideDown('slow'); 
}

but i am doing something wrong as it states an error in console, $fun(..) is not a function.

How can i make it work perfectly??

Thanks

Saswat
  • 10,704
  • 16
  • 59
  • 126

1 Answers1

2

You'd do that with bracket notation

$('#'+obj)[fun]('slow'); 

FIDDLE

But why not use a proper event handler, and slideToggle if you intend to toggle it

$('.btn_crt_acct').on('click', function() {
    $('#register_div').slideToggle();
});
adeneo
  • 293,187
  • 26
  • 361
  • 361