OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot read property 'addEventListener' of null in copycode.js

  • Thread starter Thread starter Rajitha
  • Start date Start date
R

Rajitha

Guest
When I click inspect element, I am getting error for copy clipboard tooltip:

Cannot read property 'addEventListener' of null.

Below is my JS code:

Code:
createtooltip()
var buddhaquote = document.getElementById('mytext')
buddhaquote.addEventListener('mouseup', function(e){
    var selected = getSelectionText() // call getSelectionText() to see what was selected
    if (selected.length > 0){ // if selected text length is greater than 0
        var copysuccess = copySelectionText() // copy user selected text to clipboard
        showtooltip(e)
    }
}, false)

<p>When I click inspect element, I am getting error for copy clipboard tooltip:</p>

<blockquote>
<p>Cannot read property 'addEventListener' of null.</p>
</blockquote>

<p>Below is my JS code:</p>

<pre><code>createtooltip()
var buddhaquote = document.getElementById('mytext')
buddhaquote.addEventListener('mouseup', function(e){
var selected = getSelectionText() // call getSelectionText() to see what was selected
if (selected.length > 0){ // if selected text length is greater than 0
var copysuccess = copySelectionText() // copy user selected text to clipboard
showtooltip(e)
}
}, false)
</code></pre>
 

Latest posts

M
Replies
0
Views
1
Mohit Pant
M
Top