David Van Staden
David Van Staden

Reputation: 1779

Binding Click function for one element to the click function of another

I have a click function on the following element:

$('#make article > a, #latestInner article > a').click(function (e) {...});

Now I want to bind the clicking of the above to the following:

$('#make article h4 a, #latestInner article h4 a, #models article h4 a').click(function (e) {...});

so that clicking on:

#make article > a, #latestInner article > a

will be as if I have clicked on:

#make article h4 a, #latestInner article h4 a, #models article h4 a

Upvotes: 0

Views: 75

Answers (3)

Avishek
Avishek

Reputation: 1896

Try this:

$('#make article > a, #latestInner article > a').click(function (e) {
    $('#make article h4 a').click();
    $('#latestInner article h4 a').click();
    $('#models article h4 a').click();
});

$('#make article h4 a, #latestInner article h4 a, #models article h4 a').click(function (e) {...});

Hope it helps :)

Upvotes: 0

Adeel
Adeel

Reputation: 19228

$('#make article > a, #latestInner article > a').click(function (e) {    
 ("#make article h4 a").trigger('click');    
}

Upvotes: 1

adeneo
adeneo

Reputation: 318302

jQuery's trigger() will do that :

$('#make article > a, #latestInner article > a').click(function() {
    $('#make, #latestInner, #models').find('article h4 a').trigger('click');
});

Upvotes: 2

Related Questions