Title: Targeting videos with javascript
Last modified: August 20, 2016

---

# Targeting videos with javascript

 *  [hiramhibbard](https://wordpress.org/support/users/hiramhibbard/)
 * (@hiramhibbard)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/)
 * Hi there,
 * I’m trying to figure out how to target the video to check when it has finished
   playing. I need to do something along the lines of
 * onComplete: function() {
    alert( ‘video complete’) }
 * Not exactly that, but you get the idea. I know I can use shortcode like so:
    [
   jwplayer mediaid=”221″ onComplete=”function() {alert(‘video complete’);}”] but
   the problem with that approach is that the client has to add that into the shortcode
   every time they upload a video to a post, which is impractical. I need to be 
   able to target the video with javascript from the template file.
 * Did a lot of Googling but was unable to find an actual answer to this.
 * Thanks!
 * [http://wordpress.org/extend/plugins/jw-player-plugin-for-wordpress/](http://wordpress.org/extend/plugins/jw-player-plugin-for-wordpress/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [JW Player](https://wordpress.org/support/users/longtail-video/)
 * (@longtail-video)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511315)
 * The best way to do this with the plugin is to do this in the shortcode. Otherwise,
   you are going to have to hack this into your site’s template.
 *  Thread Starter [hiramhibbard](https://wordpress.org/support/users/hiramhibbard/)
 * (@hiramhibbard)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511319)
 * Like I said, having to type that into the shortcode every time is impractical.
   Looks like I’ll have to hack the plugin :-/
 * I would definitely recommend adding the ability to add callbacks without typing
   it into the shortcode as a feature.
 *  Plugin Author [JW Player](https://wordpress.org/support/users/longtail-video/)
 * (@longtail-video)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511372)
 * How would it be easier for the client to update the events in a hacked version
   of the plugin than via the recommended, and documented, method?
 *  Thread Starter [hiramhibbard](https://wordpress.org/support/users/hiramhibbard/)
 * (@hiramhibbard)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511377)
 * It would be easier if I could just target the video via javascript from a template
   file. Obviously much easier than if a non-javascript has to remember to paste
   a bunch of javascript into a shortcode, instead of just uploading the video and
   clicking “insert into post”.
 * I definitely don’t want to hack the plugin, but it doesn’t make sense to force
   the client to have to do that extra work when normally I would just write some
   javascript that they would never have to touch (like with the non-wordpress version
   of JW player)
 *  Plugin Author [JW Player](https://wordpress.org/support/users/longtail-video/)
 * (@longtail-video)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511381)
 * You could always write that into the shortcode as well though, it works.
 *  Thread Starter [hiramhibbard](https://wordpress.org/support/users/hiramhibbard/)
 * (@hiramhibbard)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511384)
 * If you mean the code in the plugin that generates the shortcode, then yeah that’s
   what I’ll probably have to do. If you’re just talking about using the shortcode
   in a post, that’s what I’m trying to avoid, as it won’t be me adding the videos,
   it will be non-js savvy editors. I’m not sure I’m explaining my issue well enough,
   but that’s ok, I’m on the right track looking through the plugin code now.
 *  Plugin Author [JW Player](https://wordpress.org/support/users/longtail-video/)
 * (@longtail-video)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511386)
 * Yeah
 *  Thread Starter [hiramhibbard](https://wordpress.org/support/users/hiramhibbard/)
 * (@hiramhibbard)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511503)
 * For others who have this problem, you don’t need to have the callbacks in the
   shortcode, nor do you have to hack the plugin as suggested. The js just needs
   to come AFTER the javascript generated by the plugin, which is why it wasn’t 
   working for me. In my case, just adding
 * <script>
    jwplayer(‘jwplayer-1’).onComplete(function() { jQuery.colorbox.close();})
   </script>
 * worked for me (to close a colorbox once the video completed).
 *  Plugin Author [JW Player](https://wordpress.org/support/users/longtail-video/)
 * (@longtail-video)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511518)
 * Thanks for sharing!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Targeting videos with javascript’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/jw-player-plugin-for-wordpress_ffffff.
   svg)
 * [JW Player for Flash & HTML5 Video](https://wordpress.org/plugins/jw-player-plugin-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jw-player-plugin-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jw-player-plugin-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/jw-player-plugin-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jw-player-plugin-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jw-player-plugin-for-wordpress/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [JW Player](https://wordpress.org/support/users/longtail-video/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/targeting-videos-with-javascript/#post-3511518)
 * Status: not resolved