I have a hyperlink in my jsp. When we click on this, a popup overlay gets displayed and the background greys out. After closing the popup, the background bees normal. Now I want the hyperlink to be clicked automatically when the page loads. Can anyone say how we can do that?
I tried the following..
$('#ViewOutages').click(); ,
$('#ViewOutages').click();
but none of it worked.. ViewOutages
is the div id in which the hyperlink is present.
Can someone please help on this.
I have a hyperlink in my jsp. When we click on this, a popup overlay gets displayed and the background greys out. After closing the popup, the background bees normal. Now I want the hyperlink to be clicked automatically when the page loads. Can anyone say how we can do that?
I tried the following..
$('#ViewOutages').click(); ,
$('#ViewOutages').click();
but none of it worked.. ViewOutages
is the div id in which the hyperlink is present.
Can someone please help on this.
Share Improve this question edited May 22, 2013 at 5:49 Craig McQueen 43.5k32 gold badges137 silver badges187 bronze badges asked May 22, 2013 at 4:46 Phanimadhavi VasantalaPhanimadhavi Vasantala 2252 gold badges6 silver badges17 bronze badges 2- Do you want a link to be clicked specifically or a popup to be shown? – zerkms Commented May 22, 2013 at 4:48
-
1
$('#ViewOutages').find('#linkID').click();
– palaѕн Commented May 22, 2013 at 4:48
5 Answers
Reset to default 3window.onload=function(){
if(document.getElementById('test')!=null||document.getElementById('test')!=""){
document.getElementById('test').click();
}
}
This actually worked.. :)
Here you go:
$(document).ready(function() {
$("#ViewOutages").trigger('click');
}
use trigger()
$(function(){
$('#ViewOutages').trigger('click');
})
from
'ViewOutages' is the div id in which the hyperlink is present.
looks like your <a>
is inside the div ..i assume you need to use find()
or children()
$(function(){
$('#ViewOutages').find('#linkID').trigger('click');
})
Try this,
$(function(){
$('#ViewOutages').find('a').trigger('click');
// if hyperlink is in div#ViewOutages as you said in question
})
You can use $(document).ready(); function which is same as