I have this problem.
On simple instagram user page there is a Follow button, Message button and three dots button.
I need to copy listener of some button under the three dots, create new button using JS and use the same listener.
Can you please help me copying the listener? When I inspect the website and try to find what does the button do exacly, it looks like it’s runing few functions. But I can’t simply copy the code into the console.
For example I want to create new button with text "Block" and put it next to the Message button (I can do that on my own), but then make it to do the same thing as if you clicked block in the three dots.
I tried googling but I am probably not good at this enough. I am a begginer, thank you for your help.
2
Answers
To achieve this functionality , you can follow these steps in JavaScript:
Here is a basic example to illustrate this concept:
In this example:
blockListener is a placeholder function that should contain the logic for blocking the user. We create a new button dynamically with the text "Block" using
document.createElement("button")
.We attach the blockListener function to the click event of the new "Block" button using addEventListener.
The new "Block" button is inserted next to the Message button in the DOM.
You can further customize the styling and position of the new "Block" button based on your specific requirements.
Feel free to adjust the code according to your HTML structure and requirements.
Now I got what you want!
open inspect->console then select the three dot button using query (or anything else) then we consider that element as
id :button
now:this will return the function you want!
Hope it helps ^_^