View Full Version : PLZ HELP :/ setTimeOut function

11-16-2012, 02:16 PM
Hello dear codingforum members. im newbie in JS so i really ur need help. here is my question. Im working on simple modal project which is developed by eric martin. As it can be seen in the codes. it calls the modal screen when user clicks on demo link or button. however instead of clicking i would like to call tht modal screen automatically after certain time like 20sec later. so can i actually apply setTimeOut in tht JS code ? Thank u !!!



<div id='content'>
<div id='basic-modal'>

<input type='button' name='basic' value='DEMO' class='basic'/>
<a href='#' class='basic'>DEMO</a>


<!-- modal content -->
<div id="basic-modal-content">
<a href='asdasdasd'><img src="https:/asdasd.jpg" alt="asdasd"></a>

<div style='display:none'>



jQuery(function ($) {
// Load dialog on page load

// Load dialog on click
$('#basic-modal .basic').click(function (e) {

return false;

11-16-2012, 03:36 PM
try this -

// delay in milli seconds
window.setTimeout('$("#basic-modal .basic").onclick()',20000);

11-16-2012, 10:00 PM
A better alternative would be:

setTimeout(function() {$('#basic-modal-content').modal();}, 20000);

1. the first parameter to setTimeout should be a function - not a string that needs to be eval()ed into a function.
2. You don't need to simulate the click, you just need to call the code that the click calls.