Search code examples
javascriptjqueryinvision-power-board

How to register jQuery click handler inline?


The CMS I'm using (Invision Power Board) has nifty Sign In links that when clicked open a dialog instead of changing the page. I found an example of how to create such a link:

<a href="..." onmouseover="$( this ).on( \'click\', ipb.global.inlineSignin ); return false;">...</a> 

The problem is, every time the mouse is moved over the link, the click handler is added. So if I move my mouse over the link ten times and then click it, the Sign In dialog comes up ten times.

I tried changing it to:

<a href="..." onclick="ipb.global.inlineSignin; return false;">...</a> 

But that doesn't work. There aren't any errors in the console, but nothing happens when the link is clicked.

I was able to get this working, but it required some non-inline code:

<script type="text/javascript">jQuery("a.signIn").on("click", ipb.global.inlineSignin);</script>

But that's a problem, because I may have sign in links on different sections of pages (that are generated independently) and if I have the above snippet more than once, then I'm back to the same problem.

Is there any way to make this click handler work using only inline code?


Solution

  • You need to invoke the method

    <a href="..." onclick="ipb.global.inlineSignin(); return false;">...</a>