I'm confused by this line in my project:
categories-product belong to
<select> and I've seen in project someone wrote this: And I'm wondering what this basically means ?
Please could anyone explain me this?
change event to that element then this will allow to explicitly trigger that change event.
Actually, the work of
trigger() is to just execute all handlers and behaviours attached to the matched elements for the given event type. And specifying the event name as a parameter will only trigger that event. Like,
trigger('change') //triggers the change event listener only trigger('click') //triggers the click event listener only
So, your code
Will set the value of the
#categories-product and then this will explicitly trigger the
change event so that the
change action that is associated with this element is executed.
Most jQuery methods provide chaining by returning
this (which is the jQuery set you called the method on). This is an absolutely key part of the jQuery API.
val is one of those methods. So that code is doing this:
...but without having to look up the element a second time.
So it's setting the value of the select, and then triggering the
change event on it (presumably so handlers for that event do something).
To understand it better you can break this line in 2 statements
Now, it is clear that the first line sets the value and second line triggers the change event. The above is just a shorthand way of clubbing the statements into one statement.
There must be a drop down i-e
select tag in your DOM with id as
is setting some value as selected value and then triggering a change event so that if there is any listener added for change event on that selector, the callback should be executed