Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Click versus Change

I recently asked a question and posted some code, to which a suggestion was to change my click handlers on a select box to change.

My question now is this: should I always use the Change handler -- or are there situations where Click would still be appropriate (Assume I would like cross-browser compatibility).

EDIT: Here's what I gather: For things like select boxes, Change IS the way to go. For simple things, like images, there is no change, so click is the way to go.

like image 948
Dirk Avatar asked Jul 27 '09 15:07

Dirk


People also ask

What is the difference between on click and click in jQuery?

click events only work when element gets rendered and are only attached to elements loaded when the DOM is ready. . on events are dynamically attached to DOM elements, which is helpful when you want to attach an event to DOM elements that are rendered on ajax request or something else (after the DOM is ready).

What is the difference between Onclick and click?

click is a function on HTML elements you can call to trigger their click handlers: element. click(); onclick is a property that reflects the onclick attribute and allows you to attach a "DOM0" handler to the element for when clicks occur: element.

What is the difference between change and onChange?

Definition and Usage The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus, after the content has been changed.

What is click in jQuery?

jQuery click() MethodThe click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.


2 Answers

When it comes to form controls, such as text-inputs, select-boxes, check- and radiobuttons, then you should use the onChange-event. When it comes to other stuff, such as link, lists, containers etc, then you should definitely use click, since those items does not support the onChange-event.

like image 96
PatrikAkerstrand Avatar answered Oct 05 '22 22:10

PatrikAkerstrand


Click does not work x-broswer, IE does not respond to a select or option click. Change is the only option available.

like image 35
redsquare Avatar answered Oct 05 '22 22:10

redsquare