Jquery click event what was clicked
Save Article. Improve Article. Like Article. Get the ID of the clicked button. Previous jQuery click with Examples. Next How React Native works? Recommended Articles. Toggle class by adding the class name when element is clicked and remove when clicked outside. How to increase the width of a div by specified pixels once it is clicked using jQuery? Article Contributed By :. As you can see, same is the output except alert message. The following script is used in the demo:. To learn more about it go to its own chapter.
Again as you click the link and remain inside the link area the alert will be shown, which is placed inside the event handler. See example by clicking the link below:. This is a more visible example of click method where I have created five colored div elements. Each div has different color — red, green, yellow, blue and black. In front of these five div elements a larger div is given with white color.
As you click any of the colored div element, the color of larger div will be changed to the one that you clicked. So what is done in the script section of code? Each div is created with an ID for which the style is created in the style section. In style section, each colored divs are given a color. Then in jQuery section, I used click jQuery event of each div element.
In the following example, an animation is created. As you can see in the code of above example, when you click on the button, the click event triggers a function animateex that calls div element with the animate method and it starts animating with new CSS properties.
A click method is used with other events of jQuery. The variations of the JavaScript onclick method are:. The first and the second variations are a short form for. Whenever a mouse pointer is over the element and the button pressed and released, the event click is then sent to that element. The event can be received by any element of the HTML.
With the above code, if the element is clicked, the following will be displayed. Image Source. Click event can also be triggered if the other element is clicked through the following code. With this code, the message will be alerted by the element. Through the following events, only a click event is triggered. Before taking an action, the above-mentioned events are usually the desired sequence. Else, the other suitable event is the mouse down or mouse up event.
Due to the. You may also have a look at the following articles to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy. Forgot Password? This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy.
0コメント