Using ColorBox onComplete in WordPress

I’m sure I’m missing something basic, but I’ve written little jQuery code and can’t figure it out. I’m using the ColorBox plugin for my WordPress website and would like to run some code after an image is displayed. I’ve added the following code to my header.php file, but the alert is never called:

<script type="text/javascript">
    jQuery('.screenshot-image a').colorbox({
        onComplete:function(){
            alert('test');
        });
    });
</script>

Does anyone know what’s wrong?

Related posts

Leave a Reply

2 comments

  1. Next time you should check your javascript console for errors. You can’t put a semicolon after an object value like that and you’ve included an extra ‘)’. Try the following:

    jQuery('.screenshot-image a').colorbox({
        onComplete:function(){
            alert('test');
        }
    });
    

    Also, be sure to wait until the DOM has loaded before doing any of this.