(Because:
-I have one console.log into the <script> at the beggining and it works the firts time when open the website.
-I have one console.log into every one them (of the âaddEventListenerâ) but they do not appear un my console when I click).
Could somebody tell me if we can use âaddEventListenerâ in widgets HTML? If the answer is âyes, we canâ, is there a specific way?
Yeah, addEventListener works just as in any other webpage. Your issue may be caused by something else. Keep in mind that some events will not fire as is it not a full document, so your first example (window.addEventListener("load", function() {})) will not work.
With the second and third examples I have no issue. For this code Iâm receiving response:
<div>
<h3>Hello World from AngularJS directive!</h3>
<p><strong>Source</strong> is {{source.device.id}}</p>
<p><strong>Timestamp</strong> is: {{ts}}</p>
<p><strong>Value</strong> is: {{value}}</p>
<button id="myButton">Click me!</button>
</div>
<script>
// JavaScript code
document.addEventListener("click", function(event) {
console.log('Document clicked!');
console.log('Mouse coordinates:', 'X:', event.clientX, 'Y:', event.clientY);
});
document.getElementById('myButton').addEventListener('click', function() {
console.log('Button clicked! Hello from the console.');
});
</script>