Skip to main content

Simulating a click in jQuery/JavaScript on a link

$("#theElement").click();

--------------------------------------------------------------------------------

<script type="text/javascript">
$
(function(){
        $
('#thickboxButton').click(function(){
                $
('#thickboxId').click();
       
});
});
</script>

<input id="thickboxButton" type="button" value="Click me">

<a id="thickboxId" href="myScript.php" class="thickbox" title="">Link</a>

--------------------------------------------------------------------------------

$("#your_item").trigger("click");

      <a href="somewhere" id="mylink">MyLink</a> 
       
<script>jQuery('#mylink').click(function(){
           
// do whatever I want here, then redirect
             window
.location.href = "http://stackoverflow.com";
       
});
       
function doClick(){
            jQuery
('#mylink').trigger('click');
       
};
       
// trigger the redirect now
        doClick
();

        </script>

 --------------------------------------------------------------------------------