0

How to conclude an element is interactable using DOM?

I couldn't find onclick event on some elements in DOM, but they are clickable.

sites build with different framework act differently.

I have tried to loop through all elements under a class or id and if the element have a non-null onclick value a border will be drawn for the element.

Ouroborus
  • 16,237
  • 4
  • 39
  • 62
SHABEEB K
  • 1
  • 1
  • 1
    One common way of making elements interact-able is to use `addEventListener`. However this can also be undetectable once it's in place. Even if it were detectable, not all events imply interactivity. For example, `mousemove` can be used for interactivity but is also used for non-interactive tracking. – Ouroborus Jul 29 '23 at 05:33
  • Having an event listener does not mean something is interactive, nor the other way round. Especially when event delegation is used. – Bergi Jul 29 '23 at 06:41
  • https://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node-in-javascript-or-in-debugging – Bergi Jul 29 '23 at 06:44

1 Answers1

0

if you want to know if an element has an event listener or not

you can set the event listener like this :

element.onclick = () => {}

rather then this one :

element.addEventListener('click', ()=>{})

for detecting if some elements have click event set for them or not you can use:

elements.forEach((elm) => {
   if(elm.onclick == null) {
       console.log('Null')
   }else{
       console.log(elm.onclick)
   }
})

its my first answer in stackoverflow

hope it did help :)

  • In my case I am not the one who is writing the code, I am checking it , so If the event is added like element.addEventListener(",()=>{}) is there any option to find it – SHABEEB K Jul 29 '23 at 06:18