ashish gupta
ashish gupta

Reputation: 1

How to use link_to_function

If I am using statement:

`$`.link_to_function "Greeting", "alert('Hello world!')", :class => "nav_link"

It's working fine.

But If

`$`.link_to_function "Greeting", "my_function", :class => "nav_link" 

I have defined my_function in application.js

`$`.function my_function(){
    alert("my function called");
}

I am using rails 3.2.1

Thanks in advance, Ashish

Upvotes: 0

Views: 226

Answers (1)

Veraticus
Veraticus

Reputation: 16064

JavaScript function calls must always include parenthesis, even if they have no arguments. So try this:

`$`.link_to_function "Greeting", "my_function()", :class => "nav_link"

Upvotes: 1

Related Questions