I am more or less a complete beginner. What I want to do is use a bookmarklet to capture when a specific html button on a page is clicked and then start a timer. How would I go about that in javascript?
Asked
Active
Viewed 309 times
1 Answers
0
You can use generators like this to convert your JavaScript into a bookmarklet.
Example:
This script logs the first button on the page when it's clicked:
document.querySelector("input[type=button]").onclick=function(e){
console.log(e)
}
And after conversion, this bookmarklet does the same after injected into a page.
javascript:(function()%7Bdocument.querySelector(%22input%5Btype%3Dbutton%5D%22).onclick%3Dfunction(e)%7Bconsole.log(e)%7D%7D)()

Sebastian Speitel
- 7,166
- 2
- 19
- 38
-
"every button" — No, that's the *first* button on the page. – Quentin Mar 20 '18 at 15:34
-
sorry, changed the description. My intention was to show the concept – Sebastian Speitel Mar 20 '18 at 15:37
-
The generator looks useful, thanks. How would you log a specific button by name, for example? – cats00eye Mar 20 '18 at 19:21
-
give it an id or find out what id it has and use document.getElementById('the_id_you_gave_the_element') – Sebastian Speitel Mar 20 '18 at 19:23