How to call jQuery colorbox with javascript onClick event instead of a link?

DemonXTC picture DemonXTC · Dec 10, 2010 · Viewed 48.2k times · Source

I want to call colorbox using javascript rather than a href link?

anyone know how I can do this?

thanks.

Answer

Memohotel Trip Organizer picture Memohotel Trip Organizer · Jun 14, 2011

The previous examples didn't work for me, but using the same idea, this does work:

<script>
function lightbox(){    
  $.colorbox({width:"80%", height:"80%", iframe:true, href:"/pagetoopen.html"});
}
</script>

<input type="button" value="open the box" onClick="lightbox()"/>