javascript - Clipboard.js script works in view file but not in seperate .js file -


i using clipboard.js allow users copy snippets of code api docs page.

<script> var clipboard = new clipboard('.copybutton');</script> 

when run script in view functionality works should. if place script in own js file error

uncaught referenceerror: clipboard not defined 

i using yii2 framework using assets register sources so:

 public $js = [     "js/api.js", ]; 

and registering asset inside of main layout so:

use metis\assets\apiasset; apiasset::register($this); 

anyone got ideas why?

it sounds either clipboard object isn't being initialized in time, or clipboard.js file registered after script using it. can verify client source clipboard.js file defined before script using it?


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -