skip to Main Content

I mean, can I add it later on, like after I closed that div?

If I can’t add it in HTML, can I add that in CSS or JS? The thing is that I created website with WordPress and Elementor.

And I can’t edit page as HTML (edit source of html code), but I can add HTML code or CSS code or JS code.

So I want myFunction() to get runned when someone click on div which id is "e-title-2451".

2

Answers


  1. <div id="e-title-2451">click on e-title-2451</div>
    <script>
    const myDiv = document.querySelector("#e-title-2451")
    myDiv.addEventListener('click', myFunction)
    function myFunction() {
      alert('something happened')
    }
    </script>

    You can try something like:

    const myDiv = document.querySelector("#e-title-2451")
    myDiv.addEventListener('click', myFunction)
    
    Login or Signup to reply.
  2. you can use event listeners :

    document.querySelector("#e-title-2451").addEventlistener('click',()=>{
     //the function code you want to perform 
    });
    

    for class you can use (".e-titlr-2451")

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search