var element = document.getElementById("element-id");but when using jQuery it is as simple as
var element = $("#element-id");
var element = document.getElementById("element-id"); element.setAttribute("class" , "class-name");but when using jQuery, all we have to do is
Another feature of jQuery is that you can chain functions in jQuery like follows.
Not only can you select specific elements by id, but also you can select various other combinations.
$(".class-name")selects all elements of a class.
$("img")selects all elements of type "img".
So the code
$("img").addClass("class-name");will add the class "class-name" to all img elements.
By now you would have noticed that these are css selectors. But jQuery has its own selectors as well, such as the :animated selector.
Now let us look at how a plugin is invoked using jQuery. If you have included a date-picker plugin for jQuery, the usual way of invoking a date-picker would be
$("input-element").datepicker();And you will have a date-picker that looks like the following.