

Where $(this) is the object that called the function, ie the input with the onclick. jquery get certain class name of element which has several classes assigned. Also there is a big difference between (this) and this. I'd have thought that i could do this by first getting the dom element that was clicked on, ie something like this: var form = $(this).parents("form") Get class name from element, and select all elements with the same class. Well, if you really had wanted to use a jQuery function for some reason, you could have used (this).prop ('tagName') - but it's easier to just use this.tagName as ssilas777 said. Because it's a non-standard attribute, you'll need to use jQuery's attr or the DOM getAttribute method to get it: ('name'). In the confirmSubmit, i'd like to be able to dynamically get the form object (to submit it), instead of having to hardcode the form's id, or pass it as part of the call to confirmSubmit(). div elements don't have a name attribute, but most browsers will let you add one. It will select an element if the selector's string appears anywhere within the element's. This is the most generous of the jQuery attribute selectors that match against a value. Can be either a valid identifier or a quoted string. 5 Answers Sorted by: 25 Use ('form :input') Per the docs: Description: Selects all input, textarea, select and button elements. Var text = document.I have a form where i've replaced the submit button with an input (with type=button) with an onclick which calls an existing function: version added: 1.0 jQuery ( ' attribute'value'' ) attribute: An attribute name. convenience method to display unprocessed html on the same page
GET NAME OF ELEMENT JQUERY CODE
The above code is enough to get the name of the event triggered. prop('tagName'), jQuery returns the tag name of the first element in the collection, so you get 'div' as a result. (this) contains the div, and when you run. If you are inside an event handler or other jQuery method, where the element is the pure DOM node without wrapper, you can use: Both are standard DOM. .add will add an element to the current jQuery collection, in this case, (this). var className ('sidebar div:eq (14)').attr ('class') should do the trick. attr () method to get the value of an element's attribute has two main benefits: Convenience: It can be called directly. To get the value for each element individually, use a looping construct such as jQuery's. using the $ prefix to use the "jQuery wrapped var" convention Creating a plugin in jQuery, I have to get the names of input fields on which events would occur. After getting the element as jQuery object via other means than its class, then. attr () method gets the attribute value for only the first element in the matched set. Using eq() is a little more explicit making this point than the answers using map, though map or each is what you'd probably use "in real life" ( jquery docs for eq here). I want to be overly clear that you have four items that matched that selector, so you need to deal with each explicitly. With the code in the question, you're only directly interacting with the first of the four entries returned by that selector.
