Ruby on Rails Tuesday, December 27, 2011

It actually has to do with your jQuery code. `$()` actually returns a
jQuery instance with all the jQuery methods. `onclick` is not an actual
jQuery method; you need to use the alternative
[`click`](http://api.jquery.com/click/) and pass it the function. Like
so:

window.onload = function() {
$('#test_button').click(test_func);
}

function test_func() {
alert('it works!');
}

P.S. `$()` is a CSS-selector. Ergo, passing it `test_button` means that
you want the `test_button` tag. You should prefix it with the
id-selector (#).

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment