1

I already search this functionality to this url : How to trigger click on page load? but it's not working in my site.

Well, I have a page where a popup box appear when I click on a "project" link. here is the code :

$(".project").click(function() {
    $("#first, #second, .allContactsContent").slideUp("slow", function() {
    $("#third").slideDown("slow");  
    $("#contacts, #showSearchResult, #all_projects").hide();            
    });
});

I want to load this "project" click event when page is load, how can I do this ? What I am trying now is following :

<script type="text/javascript">  
$("document").ready(function() {
setTimeout(function() {
    $(".project").trigger('click');
    alert(1);
},10);
});
</script>
Community
  • 1
  • 1
Shibbir
  • 1,963
  • 2
  • 25
  • 48

2 Answers2

0

here is a working fiddle

HTML

 <div class="project"> </div>
Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48
0

You don't want a trigger a "click" event when nobody has clicked on anything. The event handler code should be refactored so a click event is not required:

function showAndHideStuff() {
    $("#first, #second, .allContactsContent").slideUp("slow", function() {
        $("#third").slideDown("slow");  
        $("#contacts, #showSearchResult, #all_projects").hide();            
    });
}

Then pass the function in as a ready event handler, as well as using that function as the click handler:

$(document)
    .ready(showAndHideStuff)
    .ready(function() {
        $(".project").click(showAndHideStuff);
    });
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92