Discussion: Lesson 1 - Introduction to jQuery
BackComments
3 messages from 3 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Comments
Hi Oxana,
thank you for your interest
Let's consider you have an application where the user can choose which event
triggers an action. In the code, we don't know which event the user chose since
it's determined when the program is running. So we'll store the event name in a
variable and use the bind()
method to respond to it:
let eventName = "click"; // This value comes from the user somehow
// it could also be let eventName = "mouseenter";
$(#element_id).bind(eventName, function() {...}); // We cannot use just .click() since there can be any event in the variable
If we knew it's always the click event we want to react to, we wouldn't need
bind()
:
$(#element_id).click(function() {...});
Is it more clear now?
3 messages from 3 displayed.