I’m using dojo. I’ve got something like this:
<a id="fooBar" onclick="foo();bar();">Foo then Bar</a>
I want to trigger fooBar‘s click handler from another button. Something like:
<a onclick="dojo.query('#fooBar')[0].click()">Do FooBar</a>
Can I do that?
or
See examples.
I haven’t used Dojo before, but can safely say that you can do better than inline events :). Moreover, these will not be managed by Dojo as they were added inline. The
onclickmethod here is a native DOM method for triggering the function attached to theonclickproperty of the element.dojo.byIdis a shortcut todocument.getElementById, and honestly you can easily do without Dojo here:Here’s the three methods with a comparison of character savings (9 and 14):
See a couple of good reasons for not using inline click handlers.