Code has been added to clipboard!

Learn to Attach Event Handler with jQuery .change() Method

Reading time 1 min
Published Dec 29, 2017
Updated Oct 9, 2019

jQuery change: Main Tips

  • The jQuery .change() method is a shortcut of using either the .on() or .trigger() method with change event as the first parameter.
  • It attaches an onchange event handler to run when the jQuery change event occurs, or invokes said event.

Usage of .change() Explained

The .change() jQuery method attaches an event handler, invoked when the value of an input element (such as <input>, <textarea>, <select>) changes.

See the example below and enter anything in the field or check a checkbox. Clicking outside it will cause an alert to pop, telling you the input value has been changed:

Example
$("input").change(() => {
    alert("Your input value has been changed.");
});

The syntax for jQuery .change() is as follows:

$(selector).change([eventData], handler)

jQuery .change() can also trigger the event itself. Follow this simple syntax for that:

$(selector).change()

As you can see, .change() jQuery method takes two arguments. The eventData is an object, which contains data passed to the event handler. The event handler is a callback function. Additionally, you can add a selector.

Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX