#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    How select only one ( that is in div, which start action )


    Hello,
    i have three div's and every div has hidden child (display none)
    when i write:

    $('.link img').click(function() {
    $('.hidden').css({'display':'block'})
    });

    Something like this works, but then ALL .hidden appears, and i want to show only .hidden that is in clicked img. (current hidden not all hidden )



    <div class="link"><p>show menu</p>
    <a href="#"><img src="images/icons/arrow.png" /></a>
    <div class="hiddenDiv"></div>
    </div>

    <div class="link"><p>show menu</p>
    <a href="#"><img src="images/icons/arrow.png" /></a>
    <div class="hiddenDiv"></div>

    </div> <div class="link"><p>show menu</p>
    <a href="#"><img src="images/icons/arrow.png" /></a>
    <div class="hiddenDiv"></div>
    </div>

    Thanks for help, because i have all the time problems with wthis approach, where ia want to select current item not all items.

    Can u explain me how it works, i dont need ready solutions, but explanation..

    THANK You all for any help.

    Mike.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    24
    Rep Power
    0
    Not sure, ( because I haven't tested it )
    but I think this works:

    $('.link img').click(function() {
    $(this).find('.hidden').css({'display':'block'});
    });

    The $(this) line returns the element that triggered the event.
    The .find() method will take a selector as parameter and search the descendants of the $(this) element.
    So in fact it searches for an element with a class of hidden inside the children of $(this).
    Then jQuery will set the display of all that elements to 'block'.

    Let me know if it works !

    Léon

IMN logo majestic logo threadwatch logo seochat tools logo