JQuery is a lightweight Javascript library or framework. Javascript is a programming language, while jQuery is a library. By using jQuery, we can use less code finishing more functions. But jQuery is slower than Javascript, especially some people like using abuse of selectors and do not use chainable functions to write.
1. Positioning element
JS
document.getElementById(“abc”)
JQuery
$(“#abc”) : This is positioning by id
$(“.abc”) : This is positioning by class
$(“div”) : This is position by tag
To pay attention that JS retruns this element, and jQuery returns a JS object, and all examples below assume that have alreay positioned the element abc.
2. Change the content of elements
JS
abc.innerHTML = “test”;
JQuery
abc.html(“test”);
3. Assign values
JS
abc.value = “valueabc”;
JQuery
abc.val(“valueabc”);
4. modify styles of elements
JS
abc.style.fontSize=size;
JQuery
abc.css(‘font-size’,18);
JS
abc.className = “aaa”;
JQuery
abc.removeClass();
abc.addClass(“aaa”);