Reputation: 1361
I have an application that has some dynamic text that opens a window to another page when clicked. It works when I click on the text in my page, but if I try to trigger the click event itself (I am working in the dev console testing new features), it doesn't trigger. Here is the simplified code I have written:
var idOfLoadedText = response.getText;
$("#" + idOfLoadedText).click(function() {
window.open('https://mtLink.com');
return false;
});
Very simple, and it works as intended in the site. However, if I go to the dev console and type in:
$("#" + idOfLoadedText).click();
It doesn't open the window. Is there something I'm doing wrong?
EDIT You are all going to hate me....I guess my system had a reset recently, and the pop-ups were being blocked.
Upvotes: 2
Views: 189
Reputation: 16979
idOfLoadedText
is likely not globally accessible. You could define it on window
, and do something like....
window.idOfLoadedText = 'hoorah' // -- or response.getText;
$('#' + window.idOfLoadedText).click(); // -- $('#hoorah').click()
but, this is likely not ideal. You'll want this somewhere globally accessable to run it in your console, perhaps somewhere better than the root of window
. If you just want to see it working, place it on window
and go for it
Check this JSFiddle Example. Open dev tools, click top frame => (result.jshell.net/) and run $('#' + window.idOfLoadedText).click()
in your console
Upvotes: 2