DevKev
DevKev

Reputation: 6304

How can I target a specific link/click in jQuery?

http://jsfiddle.net/KevinOrin/KHHDT/

After clicking open 1 of the black bars/accordions (example: "Greenhouse Gases") I have a link "More/Less info" that is suppose to toggle more information. The problem is the click function is not on the "More/Less info" element but the entire "."happening-main-text" element. Clicking anywhere in the div activates the toggle and that shouldn't be. Any ideas how to modify this jQuery to target JUST the .readmore in that div?

    // More/Less Info Why Is Is Happening
jQuery('.readmore').closest(".happening-main-text").click(function()                
{                  
    jQuery(this).children(".divmore").toggle('slow');       
    return false;                                       
});

Upvotes: 0

Views: 178

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382150

Use

jQuery('.readmore').click(function() {                  
    jQuery(this).closest(".happening-main-text").children(".divmore").toggle('slow');       
    return false;                                       
});

What you did what precisely binding the event to the enclosing ".happening-main-text" element.

Demonstration

Upvotes: 2

Related Questions