i need to add onclick="window.location.href= to all elements on my page
I heard i need to use * for all elelemts
how will code look for me to make that? hope someone can help me
will aprecte help so much, im new to programming, just learning
i need to add onclick="window.location.href= to all elements on my page
I heard i need to use * for all elelemts
how will code look for me to make that? hope someone can help me
will aprecte help so much, im new to programming, just learning
2
Answers
if you want to add a click event for all buttons, something like this will work:
To answer your question directly, to add
window.location.href = "https://example.com"
to every element on your page, you need to use the*
selector, as you mentioned. That will look something like this:That being said, it seems unnecessary to attach a click event to every single element, and probably makes more sense to attach the click event to the body element or the page itself.
If you simply meant you wanted to add it to every link or button on your page, and not actually every element, then something like this would work:
You can substitute ‘a’ and ‘button’ in the code below with any element that you want to apply the click event to.
Another method for catching the click event on multiple buttons is to add a click event to their parent div, and then check if the child element being clicked is a button.