/    Sign up×
Community /Pin to ProfileBookmark

creating a pseudo click event w/ jQuery

I want to create a sort of pseudo click event, that is needed to launch a slideshow.

when the page loads it would fire off a function that creates a clicks event, as if the user has clicked on an element, when in fact that they had not. it that possible?

i saw in the jquery documentation with the click function, you could click on one thing and then another click event would be created via another element.
that’s close to what i’m trying to

$(‘#other’).click(function() {
$(‘#target’).click();
});

big thanks in advance!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@cbVisionNov 18.2011 — That function will "click" the #target element when the #other element is actually clicked.

If you want the #target element to be clicked automatically when the page loads, you'll need to do something like this:

[CODE]$(document).ready(function(){
$('#target').click();
})[/CODE]
Copy linkTweet thisAlerts:
@toptomatoauthorNov 18.2011 — thank you, but i'd already tried that. that's just a click handler,..no?

it won't run unless it's clicked.

$(document).ready(function(){

$('#launch').click(function(){
alert('i was clicked');
});

});
Copy linkTweet thisAlerts:
@cbVisionNov 18.2011 — No, you're telling it to click it. You bind an event handling by:

[CODE]$('#target').click(function(){
... onclick stuff
});
[/CODE]


This will simply execute the click function.
[CODE]$('#target').click();[/CODE]
Copy linkTweet thisAlerts:
@cbVisionNov 18.2011 — Here's an example:

http://jsfiddle.net/dfreema1/AGTte/3/


It should execute the launch click action without having to click.
Copy linkTweet thisAlerts:
@toptomatoauthorNov 18.2011 — i'm sorry but i don't understand. the code below will not run the alert function without having first clicked on id 'launch'. as you know, i'm trying to create without the user having to click on #launch,


$(document).ready(function(){

$('#launch').click(function(){
alert('i was clicked');
});

});

thanks!
Copy linkTweet thisAlerts:
@cbVisionNov 18.2011 — right, because that code is only binding an onclick action. You then need to add $('#launch').click(); to call the function!

[CODE]
$(document).ready(function(){
$('#launch').click(function(){
alert('i was clicked');
});

[B]$('#launch').click();
[/B]

});[/CODE]
×

Success!

Help @toptomato spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...