I'm trying to simulate a click in a html page I have, but it only works after I click on Inspect element with the Chrome console
When I run the command in the console what I get is this
$('#toolbar-preview').click();
n.fn.init {context: document, selector: "#toolbar-preview"}
If I press inspect element the behaviour changes in
$('#toolbar-preview').click();
me.fn.init [a#toolbar-preview.link.icon-only]
and the buttons gets properly clicked from then on.
I'm not an expert at all in javascript so I don't know what the issue is about, is it maybe an initialization issue of the button?
EDIT I don't know If I'm analyzing correctly, I think that what gets called is this, got this from the analyzing feature:
var g = function(e, t) {
return t = null == t ? e.length - 1 : +t,
function() {
for (var i = Math.max(arguments.length - t, 0), a = Array(i), n = 0; n < i; n++)
a[n] = arguments[n + t];
switch (t) {
case 0:
return e.call(this, a);
case 1:
return e.call(this, arguments[0], a);
case 2:
return e.call(this, arguments[0], arguments[1], a)
}
var o = Array(t + 1);
for (n = 0; n < t; n++)
o[n] = arguments[n];
return o[t] = a,
e.apply(this, o)
}
}
and
on: function(e, i, a, n) {
function o(e) {
var n = e.target;
if (t(n).is(i))
a.call(n, e);
else
for (var o = t(n).parents(), r = 0; r < o.length; r++)
t(o[r]).is(i) && a.call(o[r], e)
}
var r, s, l = e.split(" ");
for (r = 0; r < this.length; r++)
if ("function" == typeof i || !1 === i)
for ("function" == typeof i && (a = arguments[1],
n = arguments[2] || !1),
s = 0; s < l.length; s++)
this[r].addEventListener(l[s], a, n);
else
for (s = 0; s < l.length; s++)
this[r].dom7LiveListeners || (this[r].dom7LiveListeners = []),
this[r].dom7LiveListeners.push({
listener: a,
liveListener: o
}),
this[r].addEventListener(l[s], o, n);
return this
}
I found the lines above following from here

EDIT2: What I was able to understand for my issue is that it is caused by not having access to the iframe of the page. When I inspect an element the iframe gets exposed and then I can use queries and such to run commands like click. Is there a way to properly access an element inside the iframe with js? I have tried a couple of things but to no avail:
frameRef.contentWindow //I have no function to search for elements like "getElementById('')"
frameRef.contentWindow.document//this is null
frameRef.contentDocument//this is null