I am very new to javascript I know that you can add an onclick=”” event to a html element… but is it possible in the javascript itself to declare that when someone clicks on x element an event is triggered?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Make sure that you either run this after the element already exists (scripts at the bottom), or when the DOM is ready. (You could use
window.onloadfor that, but you might just want to use jQuery from the beginning so that, among other things, you get a magical DOM-ready function.onloadhas some downsides, like waiting for images to load.)