0

I'm struggling with what I would think would be a rather simple jquery function. I have text with a span around it with the class "commentreply". I'm trying to create a jquery feature that inserts a form directly under the text that users can use to reply to a comment.

For some reason I cannot for the life of me get jquery to select the "commentreply" class in order to manipulate the DOM via a click.

<script type="text/javascript">
$(document).ready(function(){
$(".commentreply").click(function(){
$(this).html( "the form code would go here" );
}

}
</script>

<span class="commentreply">Reply</span>

Does this make sense? It seems rather simple but I've been making small changes trying to get the darn thing to work for about 3.5 hours now.

2 Answers 2

3

You are missing the closing parentheses around your event handler (click and ready) functions:

$(document).ready(function(){
    $(".commentreply").click(function(){
        $(this).html( "the form code would go here" );
    });
});

Note the closing parentheses on the final 2 lines. Also notice that I have added a semi-colon at the end of those lines - it will work without them, as you have it, but it's always best to include them. Other than that, it should work fine.

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

3 Comments

@bill Do you use Firebug or any other browser development tool? It can help you avoid these sorts of simple syntax errors.
Yes I do use firebug. But honestly, I haven't figured out how to use it for javascript. I've been working with php for about a year now but am just entering the world of javascript/jquery.
@James, Yes this was correct and the code is now working thank you.
0

This works for me:

$('#id a').live('click',function(){
  $(this).html( "the form code would go here" );
});

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.