Is there any way to get the ID of the element that fires an event? I’m thinking something like: Except of course that the var test should contain the id “aaa”, if the event is fired from the first form, and “bbb”, if the event is fired from the second form. Answer In jQuery event.target always refers to the element
Tag: jquery
How do you remove all the options of a select box and then add one option and select it with jQuery?
Using core jQuery, how do you remove all the options of a select box, then add one option and select it? My select box is the following. EDIT: The following code was helpful with chaining. However, (in Internet Explorer) .val(‘whatever’) did not select the option that was added. (I did use the same ‘value’ in both .append and .val.) EDIT: Trying
Is there an “exists” function for jQuery?
How can I check the existence of an element in jQuery? The current code that I have is this: Is there a more elegant way to approach this? Perhaps a plugin or a function? Answer In JavaScript, everything is ‘truthy’ or ‘falsy’, and for numbers 0 means false, everything else true. So you could write: You don’t need that >0