I'm developing a Chrome Extension and getting the error "Uncaught TypeError: Cannot read property 'click' of null". It works in the console and I made sure to close the console. I'm trying to run this on the site below.
https://realtime.demo.sonicwall.com/main.html
popup.js
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', int);
});
function int() {
var source = document.getElementById('j1_64_anchor').click;
}
var coll = document.getElementsByClassName("collapsible");
var i;
popup.html
<body>
<button class="collapsible">Interfaces</button>
<div class="content">
<button onclick="int()" class="collapsible">Interfaces</button>
</div>
</body>
In your html
there is no element with id j1_64_anchor
. So your code document.getElementById('j1_64_anchor').click();
will fail.
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', int)
});
function int() {
console.log('calling');
var source = document.getElementById('j1_64_anchor').click();
}
var coll = document.getElementsByClassName("collapsible");
var i;
<button class="collapsible">Interfaces</button>
<div class="content" id="j1_64_anchor">
<button onclick="int()" class="collapsible">Interfaces</button>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With