jQuery showing comment box

SurrounD

I'm trying to learn some jQuery to add to a website I am creating. When the user clicks the "Add Comment" link a text area and post comment button appears but I can't seem to get it to work..

<html>
<head>
    <script type="text/javascript" src="jquery-1.10.0.min.js"></script>
    <script type="text/javascript" language="javascript">
        $("#addcomment").click(function () {
            $("#postComment").show("slow");
        });
    </script>
    <title></title>
    <link rel="stylesheet" type="text/css" href="test.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <div id="addcomment">
    <a href='#' id="addcomment" class="addcomment">add comment</a>
    </div>
    <div id="postComment" class="postComment">
    <textarea name="comment" id="comment" class="comment"></textarea>
    <input type="submit" value="Post Comment"/>
    </div>
</body>

and the CSS

#postComment{
display: none;

I have tried it on http://jsfiddle.net/2dA3p/2/ without issue but when running in with netbeans I have no luck. I hopefully there is a simple fix or something stupid I am doing.

PS this is my first post so hopefully I have followed the rules correctly :S

Thanks

nbrooks

You have to register your handler after the element already exists, so it must be wrapped in a DOM ready handler. In jQuery, the syntax for this is to wrap the code in $(function() {});

Additionally, the element IDs must be unique, or it's undefined which one the handler will actually be bound to (usually it's the first in the DOM tree that jQuery encounters).

If the event needs to be bound to multiple elements, use the class attribute instead of the ID attribute, then use a class selector.

$(function () {
    $("#addcomment").click(function () {
        $("#postComment").show("slow");
    });
});

Possible markup (minus the superfluous classes, but you can re-add them if you need to, no harm):

<div id="container">
    <div id="mainContent">
        <div id="addcomment"> <a href='#'>add comment</a></div>
        <div id='postComment'>
            <textarea name='comment' id='comment'></textarea>
            <input type='submit' value='Post Comment' />
        </div>
    </div>
</div>

jsFiddle Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Disqus comment box not showing (at all)

From Dev

text box not showing for author and comment

From Dev

comments not showing up - facebook comment box

From Dev

jQuery Datepicker icon showing below the input box instead of on the right

From Dev

jQuery Datepicker icon showing below the input box instead of on the right

From Dev

Boostrap Modal Box Not showing up while checking conditions in JQuery

From Dev

Sphinx todo box not showing

From Dev

not showing alertdialog box

From Dev

Text not showing in text box

From Dev

showing rows in a combo box

From Dev

Creating a comment box using jquery and works inside coldfusion

From Dev

jquery - showing box with if statement by click on button when field is completed - quiz creation

From Dev

Showing suggestion box when typing in input box

From Dev

Showing COUNTIF results in a Message Box

From Dev

tooltip box not showing using css

From Dev

Panda's boxplot but not showing the box

From Dev

grunt serve on vagrant box not showing

From Dev

Box plot showing mean as a line

From Dev

Color Dialog box not showing up

From Dev

Panda's boxplot but not showing the box

From Dev

Showing suggestions in a text box in angularjs

From Dev

Not showing a red rectangle box on Face

From Dev

Values not showing on JavaFX combo box

From Dev

TeamCity with showing a modal dialog box

From Dev

Colorbox is not showing content box correctly

From Dev

Datatables - showing/hiding with select box

From Dev

HTML box of colour is not showing up

From Dev

JavaFX Webview not showing alert box

From Dev

Quantity Box not showing values in Shopify