DemonXTC
DemonXTC

Reputation: 151

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

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

anyone know how I can do this?

thanks.

Upvotes: 15

Views: 49031

Answers (4)

jeremysawesome
jeremysawesome

Reputation: 7254

This is off the top of my head. But I believe you could do something like this:

<script type="text/javascript">
function call_cbox()
{
   jQuery.colorbox({html:'<p>Hi There I was instantiated onclick!</p>'});
}
</script>
<a href="#" onclick="call_cbox(); return false;">Give me a colorbox... NOW! And don't forget the color.</a>

Upvotes: 5

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()"/>

Upvotes: 19

nixis
nixis

Reputation: 510

$("tr").click(function () { 

    $.colorbox({width:"900px", height:"600px", iframe:true, href:"http://www.google.com"});

});

Upvotes: 0

Adam Luz
Adam Luz

Reputation: 29

A mix of the two answers above worked for me:

<script>
function call_cbox()
{
jQuery().colorbox({width:"900px", height:"600px", iframe:true, href:"/newsletter.html"});
}
</script>

Upvotes: 2

Related Questions