Reputation: 1
Hi friends I am trying many ways to onloading the page click the anchor tag using jquery or JavaScript.
must see the rel attribute .
<div id="local">
<a id="fmp-button" href="#" rel="http://google.com">
click
</a>
</div>
<script>
//$('#fmp-button').trigger('click');
//$("a[href='#']").click();
//$('#fmp-button').click();
//$('#fmp-button')[0].click();
//$(function(){
// window.location.href = $('#fmp-button').attr('href');
//});
</script>
I am tried all the ways Any one help me how to click the anchor tag when time of page loading anchor tag must be rel attribute
Upvotes: 0
Views: 1402
Reputation: 5166
here's another way...
<div id="local">
<a id="fmp-button" href="#" rel="http://google.com">click</a>
</div>
<script src="//code.jquery.com/jquery.js"></script>
<script>
$(document).on('click', '#fmp-button' ,function() {
var url = $('#fmp-button').attr('rel');
window.location.replace(url);
});
</script>
Upvotes: 0
Reputation: 1595
If you want to just change the page, then this will do:
window.location = $('#fmp-button').attr('rel');
Upvotes: 1
Reputation: 96
I think you need to do
<div id="local">
<a id="fmp-button" href="http://google.com">
click
</a>
</div>
<script>
$(function(){
$('#fmp-button').click();
});
</script>
Upvotes: 0