How can I get the ID of an element using jQuery?

or even : and reason behind usage of $(‘#test’).get(0) in JQuery or even $(‘#test’)[0] is that $(‘#test’) is a JQuery selector and returns an array() of results not a single element by its default functionality an alternative for DOM selector in jquery is which is different from .attr() and $(‘#test’).prop(‘foo’) grabs the specified DOM foo property, while $(‘#test’).attr(‘foo’) grabs the specified HTML foo attribute and you can find more details about differences here.

what does jQuery data() function do

Its really useful for associating various objects, strings, arrays, etc with a DOM element. Here is a fun hypothetical use: This would select every a tag, and set Orange if its odd, or Purple if its even. This is not the most optimal way to write this code if this is what you really wanted to do, but it does illustrate … Read more

$.ajax – dataType

contentType is the HTTP header sent to the server, specifying a particular format.Example: I’m sending JSON or XML dataType is you telling jQuery what kind of response to expect.Expecting JSON, or XML, or HTML, etc. The default is for jQuery to try and figure it out. The $.ajax() documentation has full descriptions of these as well. In your particular case, the first is asking for … Read more

Should I use .done() and .fail() for new jQuery AJAX code instead of success and error

As stated by user2246674, using success and error as parameter of the ajax function is valid. To be consistent with precedent answer, reading the doc : Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead. If you are using the … Read more

jQuery equivalent of JavaScript’s addEventListener method

Not all browsers support event capturing (for example, Internet Explorer versions less than 9 don’t) but all do support event bubbling, which is why it is the phase used to bind handlers to events in all cross-browser abstractions, jQuery’s included. The nearest to what you are looking for in jQuery is using bind() (superseded by on() in jQuery 1.7+) … Read more

How can I get the ID of an element using jQuery?

The jQuery way: In your example:  Run code snippetExpand snippet Or through the DOM: or even : and reason behind usage of $(‘#test’).get(0) in JQuery or even $(‘#test’)[0] is that $(‘#test’) is a JQuery selector and returns an array() of results not a single element by its default functionality an alternative for DOM selector in jquery is which is different from .attr() and $(‘#test’).prop(‘foo’) grabs the specified … Read more