The mouseup()
method triggers the mouseup
event when the left mouse button is pressed and released over a selected element. It is a short-hand of the on('mouseup', eventHandler)
event.
$(selector).mouseup(function())
This method accepts only one parameter, which is a function invoked when triggered by the mouseup()
method.
Let’s look at the code below to understand how it works.
HTML
div
with id="content"
.jQuery
script.JavaScript
mouseup()
method on the element with the id of content ("#content"
).css()
method to change the background color of that element ("#content"
) when mouseup()
is invoked.randomColor
, which generates a random color and returns it.The mouseup()
method is invoked once we press and release the left mouse button over the square. As a result, the background color of the square changes.