Is it possible to do something like this
$('#idone').click(function(){
alert('we do stuff!');
});
$('#idtwo').click(function(){
$('#idone').click();
});
... i guess not, but are there any possible workarounds?
!UPD:
Well, ok. It's a little bit more complicated. I have a jCarousel analog installed - JQueryTOOLS - Scrollable - I guess that's what its name the link: http://flowplayer.org/tools/demos/scrollable/gallery.html
I presume that it has click() event somehow hardcoded in it and when i click thumbs the plugin scrolls it to center position. Then I've bound another click event, so that I can display large image. It works similar to the example in the link above
Now I have to make this big image clickable, so clicking it I can proceed to next image in gallery, I did that, but now I have to make the carousel scroll automatically to the next thumb when I am clicking this big image. So, if I simplify my code, the essence is still smth like that:
$('#idone').click(function(){
alert('we do stuff!');
});
$('#idtwo').click(function(){
$('#idone').click();
});
where #idone is a thumb in the gallery, #idtwo is that preview image. I dont know what function is bound to click by default. Another thing: my guess was that binding the same event to the same object should replace the previous - it appears not necessarily.. And I'm pretty sure that it is exactly click();, not mouseup\down etc. cause calling
$('#idone').click();
on page load does the trick and carousel scrolls to the thumb with id="idone"
just in case: jquery-1.3.2.js
thanks everyone for your answers, and excuse me my lame English, no time for brushing up (:
!UPD:
ok! so I gave up on this one )) But to close this question and put an end to this discussion i have to know. All you people, who wrote that it is possible and suggested variants. HAVE YOU TRIED THEM?! Do they really work for you? Is it me, who is wrong? And - Thanks anyway!
To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.
and a trigger to execute the button1 click event handler. $("#button2"). bind("click", (function () { alert("Button 2 is clicked!"); $("#button1").
If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.
The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.
This would be another possiblity:
$('#idone').click(function(){
alert('we do stuff!');
});
$('#idtwo').click(function(){
$('#idone').trigger('click');
});
edit: I just see that your code should work like that already.
Define a separate function which is called by both events?
function doSomething() {
alert('we do stuff!');
}
$('#idone').click(doSomething);
$('#idtwo').click(doSomething);
or simply
$('#idone, #idtwo').click(doSomething);
[EDIT - jQuery Scrollable]
Have you tried using this with the thumbnails in jQuery Scrollable:
$('#idone').next();
(I presume #idone is scrollable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With