简体   繁体   中英

Trigger event to click a link

I have a hidden link and a button. I want when users click on the button they will go to the link. Why I'm not just show the link so users can click through the link because I don't want users see the link that appear at the bottom of browser.

<a id="stack" href="http://stackoverflow.com/"></a>
<button id="goTo">Stackoverflow</button>

Is it possible?

Maybe like this :

$(document).ready(function(){
    $("#goTo").on('click',function(e){
        e.preventDefault();
        window.location = $("#stack").attr('href');
    });
});

Add simple jquery to relay the click on the button. You can leave the a link out.

$("#goTo").click(function(){
 window.location = "http://stackoverflow.com/";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM