2

Here's what I'm using:

application.js:

$('#hfb').mouseup(function(){
$('#hideform').css('display', 'none');
});

the head from application.html.erb:

<head>
<title>CommentsApp</title>
<%= stylesheet_link_tag 'application', 'grid' %>
<%= javascript_include_tag  "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag  "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" %>
<%= javascript_include_tag "jquery-rails.js" %>
<%= javascript_include_tag "application.js" %>

<%= csrf_meta_tag %>
</head>

and the thing I want to hide:

<a href="" id="hfb">Hide Form</a>
<div id="hideform">
<% form_for Comment.new, :remote => true do |f| %>
#form stuff
<%= f.submit "Add comment" %>
<% end %>
</div>

What am I missing here ?

1
  • can you please post the rendered output in html, instead of the erb code? Commented Feb 16, 2011 at 18:18

2 Answers 2

3

I'm not sure why you are trying mouseup, I'd just use click() and hide()

$(document).ready(function() {
  $('#hfb').click(function(){
    $('#hideform').hide();
    return false;
  });
});

It also might be reloading the page, so returning false from the handler is a good idea.

edit idlefingers has a good idea too. you can't run the handlers until the document is ready.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answers, seems I had to use return false as well :)
2

You need to use $(document).ready in your js. Also, you could use jQuery's 'hide' method rather than changing the css explicitly (that's all hide does - it just reads a littler nicer):

$(document).ready(function() {
  $('#hfb').mouseup(function(){
    $('#hideform').hide();
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.