i have a problem with my jquery but unable to find why.
When i click for the first time on my link, nothing happen. On the second click, my link work. here is my code.
aplication_helper.rb
def link_to_share(name, url)
link_to_function(name, "share_link(name, url)")
end
my jquery file
function share_link(link, url)
{
$(link).click(function() {
window.open('http://www.facebook.com/sharer.php?u='+ url, 'popupwindow', 'height=430,width=500')
});
}
my view
<%= link_to_share 'Share', request.url %>
If i change my jquery function like
function share_link(link, url)
{
$(link).live('click', function() {
window.open('http://www.facebook.com/sharer.php?u='+ url, 'popupwindow', 'height=430,width=500')
});
}
the script stop working.
in my Firebug debugger, i have no error on the first click, and in the second try with the live function, no error too.
I use jquery-uij from gemfile.
thanks.
To make your code work, remove the click handler
And just leave
You don’t need to define the click handler, because you’re using the link_to_function helper. The link_to_function helper, just calls the function you entered when you click that link.
For more information, check out the documentation. I didn’t know about this helper, thanks for asking this question.