Clipboard.js: Cannot read property 'addEventListener' of null - clipboard.min.js:7

Created on 5 Feb 2016  路  6Comments  路  Source: zenorocha/clipboard.js

I've linked the script but before using it I'm getting this error in console.

question

Most helpful comment

I had the same problem and found the solution over here:
http://stackoverflow.com/questions/26107125/cannot-read-property-addeventlistener-of-null

Wrap the instantiation code in window.onload=function()

i.e.

window.onload=function(){
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
console.log(e);
});
clipboard.on('error', function(e) {
console.log(e);
});
}

All 6 comments

did you try wrapped in dom-ready event?

I've just included this file and cannot use due to this jquery error.

Everything seems to be working over here (see demo folder).

The only way we can help you is by providing a minimal example on JSFiddle.

I had the same problem and found the solution over here:
http://stackoverflow.com/questions/26107125/cannot-read-property-addeventlistener-of-null

Wrap the instantiation code in window.onload=function()

i.e.

window.onload=function(){
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
console.log(e);
});
clipboard.on('error', function(e) {
console.log(e);
});
}

Having this issue, but it was working fine when the code was on the page. Moved the code it it's own js file and now it's not working.

Does the dependency have to be after the element containing the data to be copied?! I'm having this problem as well. I put the dependency in the <head>, right after the jQuery dependency, and in my script file, I said

$(document).ready(function() { /* some other important stuff */ var clipboard = new Clipboard('#link'); });
and it didn't work. However, when I moved that to the front of the script (before the $(document).ready() stuff) I got this error. MVCE coming in a few days....

Was this page helpful?
0 / 5 - 0 ratings