开发者

jQuery chunk not running

I have the following jquery below. When the user clicks .commentCount, I want this div called #commentSec to open up, and then some other elements on the site change. This jquery chunk runs fine.

However, the second chunk, onclick of a close button called .closeComments, doesn't run at all. What am I doing wrong? Do I have to return true or something in the first jquery section?

 $('.commentCount').click( function() {
        $('#commentSec').css({ 'display' : 'inline', 'height' : 'auto', 'padding' : '10px', 'padding-bottom' : '0px', 'margin-bottom' : '10px', 'margin-left' : '10px', 'z-index' : '10'});
        $('#commentSec h3').css({ 'display' : 'block'});
        $('#rightcolumn').css({ 'opacity' : '.3'}); //Transparent rightcolumn
    });

Second Chunk:

$('.closeComments').click( function() {
    $('#commentSec').css({ 'display' : 'none'});
    $(this).css({'opacity' : '.9'});
    $('#rightcolumn').css({ 'opacity' : '1'}); //Undo transparent rightcolumn
});

HTML/PHP:

<h3><b>' . $useranswering . '\'s</b> ANSWER</h3><img class="closeComments" src="../Images/bigclose.png" alt="close"/>
    <span><a class="prev" >&larr; previous answer</a><a class="next" href="">next answer &rarr;</a></span>
    <div>
    <开发者_JAVA百科p>' . $answer . '</p>
    <form method=post>
            <input type="hidden" value="'. $ansid .'" name="answerid">
            <textarea rows="2" cols="33" name="answercomment">Comment on this answer</textarea>

            <input type="image" src="../Images/commentSubmit.png"/>


only issue that comes to my mind is that probably you might have multiple [XX comments] links, and having multiple [commentsSec]

now, you can only have one block with one ID. here is perfectly working example:

<style>
    .comment { display: none;}
</style>
<div class="comment-container"><span class="open-comment">[xx comments]<
    <div class="comment">Lorem Ipsum<span class="close-comment">[close]<
</div>
<div class="comment-container"><span class="open-comment">[xx comments]<
    <div class="comment">Lorem Ipsum<span class="close-comment">[close]<
</div>
<script>
    $(document).ready(function(){
        $(".open-comment").click(function(){
            $(this).parent().find(".comment").show({duration: 1000});
        });
        $(".close-comment").click(function(){
            $(this).parent().hide({duration: 1000});
        });
    });
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜