JavaScript: A powerful language in web development
JavaScript is a scripting language that is used to add interactivity to our web pages. It is one of the three core technologies alongside HTML and CSS which are used to create web pages.
JavaScript is supported by all the web browsers and the web browsers have a built-in JavaScript engine to identify JavaScript code and work with it. Thus, JavaScript is majorly a client-side language.
jQuery: A library developed from JavaScript
jQuery is a library of JavaScript which is built from it. It is the most popular JavaScript library. jQuery is free, an open-source library, licensed under the MIT License. This has a powerful feature of cross-browser compatibility. It can easily handle cross-browser issues that we can face with JavaScript. Thus many developers use jQuery to avoid cross-browser compatibility issues.
Why jQuery is created and what are the special capabilities of jQuery?
In JavaScript, we have to write a lot of code for basic operations while with jQuery the same operations can be done with a single line of code. Therefore developers find it easier to work with jQuery than with JavaScript.
DOM Traversal and Manipulation
In JavaScript:
We can select a DOM element in JavaScript using the document.getElementById() method or by using the document.querySelector() method.
var mydiv = document.querySelector(“#div1”);
//Or
document.getElementById(“#div1”);
In jQuery:
Here, we will have to only use the $ symbol with the selector in brackets.
$(selector)
$("#div1") – The selector is an id ‘div1’
$(".div1") – The selector is a class ‘div1’
$("#P") – The selector is the paragraph in the Html page
Adding styles in JavaScript:
document.getElementById ('myDiv').style.backgroundColor="#FFF"
Adding styles in jQuery:
$('#myDiv').css (‘background-color','#FFF');
Reference: https://www.edureka.co/
0 comments:
Post a Comment