1

I have a javascript a portion of this is as given below which on clicking an anchor tag with class to_comment will show up text box within div classes mentioned in the js.

$(".to_comment").live("click", function(){
$(this).parents(".activity_content").find(".activity_new_comment").show();
$(this).parents(".activity_content").find(".input_new_comments").click();  
$(this).parents(".activity_content").find(".input_new_comments").focus();
return false;
});

I have this simple anchor tag in a page in the slim file as :

= link_to("Comment", "#", :class => "to_comment")

And I have hardcoded the text area to appear in the div tag in a _new.html.slim partial as follows:

.activity_new_comment style="display: block;"
  .actor_logo_new_comment style="display: none;"
    .activity_content
      .actor_name_new_comment style="display: none;"
      form#new_commentactivity_22.new_comment accept-charset="UTF-8" action="/comments" data-remote="true" method="post"
        div style="margin:0;padding:0;display:inline"
          input#comment_owner_id name="comment[owner_id]" type="hidden" value="2"
            input#comment__activity_parent_id name="comment[_activity_parent_id]" type="hidden" value="22"
              .input_new_comments_container
                textarea#comment_text_activity_22.input_new_comments cols="40" name="comment[text]" rows="1" style="color: rgb(102, 102, 102);"
            #copy_comment_text_activity_22.copy_new_comment Write a comment...
                  .activities_comment_btn style="display: none;"

But the hyperlink on clicking doesnt load the text area in the corresponding div tag from the partial. The js file is loading in the browser and a sample alert is also working !!

1
  • Are you getting any errors via firebug? Commented Feb 17, 2012 at 11:33

2 Answers 2

1

Try putting your Javascript code in a block

$(document).ready(function() {
  // code here
});

to ensure the code gets executed after the dom is loaded completely. Otherwise it may happen that your HTML is not loaded completely when Javascript it trying to find elements having the to_comment class.

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

Comments

0

The first thing I notice is that .actor_logo_new_comment is set to display: none, yet there are no calls to show it in your code. Note that calling .show() on an element won't show all of it's children - you'll need to call .show() on the hidden elements directly.

1 Comment

$(selector).show(). The code to do it is all in your original post - I'm sure with a little experimentation and reading my answer you'll figure it out :)

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.