JQuery function



  • There's this code.

    $(document).ready(function(){
        $(".hide").click(function(){
            $(".open_comment").fadeIn("slow");
            return false;
        });
    });
    

    $(document).ready(function(){
    $(".open").click(function(){
    $(".open_comment").fadeOut("");
    return false;
    });
    });

    The marking is this:

    <div class="hide_comment">
    <a class="hide" href="#">посмотреть комментарий</a>
    </div>
    <div class="open_comment">
    <p>dfgdfgdfg</p>
    <a class="open" href="#"></a>
    </div>

    The thing is, these are blocks 3. The remaining two blocks, which are located below, are also open when applied to the reference .hide.
    Show me how to solve this problem so that only a specific block can be opened.



  • The problem is that the selter $(".open_comment") chooses. All Elements on the page with this class.

    You just need to pick the right element, relative to the current compressed.

    <div class="hide_comment"> 
        <a class="hide" href="#">посмотреть комментарий</a> 
    </div> 
    <div class="open_comment"> 
        <p>dfgdfgdfg</p> 
    </div>
    

    For this marking:

    compressed component <a class="hide"to get to the right. open_comment You need to take the next element for the parent.

    inside jQuery this indicates the compressed component

    $(document).ready(function(){
        $(".hide").click(function(){
    
        $(this).parent() // родитель  class="hide_comment"
               .next() // следующий элемент  &lt;div class="open_comment"&gt; 
               .fadeIn("slow");
        return false;
    });
    

    });

    for .open similar, except that the parent will be the necessary element.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2