Solution 1 :

Try trigger


Solution 2 :

Do you want an auto click or manual click?

If you want an auto =>
jQuery(‘li#refShare a:first’).trigger( “click” );
Otherwise manually means assign one id to this href and make it click.
jQuery(‘li#refShare a:first’).attr(“id”, ‘some_id’);

outside Ajax

  jQuery('#some_id').on('click','#some_id', function() {
    //do it your stuff...

Solution 3 :

Try this




    		jQuery('#Link_xyz').attr("href", '');
	        jQuery('#Link_xyz').attr("target", 'blank');

    	}, 3000);

    	jQuery(document).on('click', '#Link_xyz', function(){  

    		var target = jQuery(this);

    		var url = target.attr('href'); alert("click: "+url); 

    		//, '_blank');

            window.location.href = url;


<script src=""></script>
	<a id="Link_xyz" href="">Link</a>

Solution 4 :

You need to choose the right element which can be clickable and your goal to redirect to somewhere else automatically(where human intervention does not require) can be achieved by using ‘trigger’ function.

you can do :


For further details/documentation about jquery ‘trigger’ function, you can check this url: .trigger()

Problem :

I am dynamically creating the link on anchor tag through jquery, I want to trigger click event as soon as link gets attached to href, but in my case click event didn’t get triggered.


        url: base_url+"create-refer",
        cache : false,
        dataType: 'json',
        data: { email:email },  
            jQuery('li#refShare a:first').attr("href", '';
            jQuery('li#refShare a:first').attr("target", 'blank');
            jQuery('li#refShare a:first').click();


<li id="refShare">
<a href="" id="share-facebook">
<i class="fa fa-facebook fa-2x" aria-hidden="true"></i>


Comment posted by user3653474

tried but it is not working

Comment posted by John Archer

Sorry, my first comment was misleading (I deleted it). Do you reach the success callback? Can you

Comment posted by user3653474

yes i’m getting link and it is getting attached but click event is not triggered as soon as link is attached

Comment posted by John Archer

Does it work if you don’t set the target (to blank)? Because of popup blockers of your browser.

Comment posted by’

or you can just do‘

Comment posted by user3653474

Thanks but it is not working i tried this‘’, ‘_blank’); it is working

Comment posted by Kelsnare

I hope you tried with the correct selector

Comment posted by This answer

This answer

Comment posted by John Archer

@Kelsnare It is not true that

Comment posted by user3653474

i want auto click i tried your code but it is not working

Comment posted by Balamurugan A.

Best you analyze the jQuery.trigger(); this going to help you.

Comment posted by user3653474

Thanks but it is not working i tried this‘’, ‘_blank’); it is working

Comment posted by Nico Haase

Please add some explanation to your answer by editing it, such that others can learn from it