Saturday, May 23, 2015

Trigger a click in jQuery




To trigger a click in jQuery, for example id stakeholderAccesses:
   $('#stakeholderAccesses').click();
 I found following trigger function not working well:
 $('#stakeholderAccesses').trigger('click');
Complete example:
$(document).ready(function() {

        //Display and Load the body part when the header is clicked.

        $('#stakeholderAccesses').click(function() {
                if( $(this).parent().children('div').css("display") == "none" ) {
                        $(this).html( '-' + $(this).html().substring(1) );
                        $(this).parent().children('div').load('../_ajaxParts/CVS/CVS_Access.php', {sid: $.url.param('sid')}).show('fast');
                }
                else {
                        $(this).html( '+' + $(this).html().substring(1) );
                        $(this).parent().children('div').hide('fast');
                }
        }).hover(function() {$(this).css('cursor','pointer');},function() {$(this).css('cursor','auto');});

         $('#stakeholderAccesses').click();
});

No comments:

Post a Comment