Monday, May 13, 2019

CLIENT-SIDE DEVELOPMENT 1 JQUERY

Is jQuery a framework or a library?

Framework and libarry are not necessarily mutually exclusive terms. Framework is typically a libarry or a collection of libraries.
Strictly speaking, jQuery is a library, but, to an extent, it does meet the definition of a software framework. Although many would argue that jQuery doesn't meet the definition of a software framework strictly enough, the fact is that no other JavaScript framework fully meets the definition of a framework either.
One of the defining characteristics of a software framework is that its code is protected from modifications. In JavaScript, this clearly isn't the case. Any libraries or frameworks that can be called into your client-side code are modifiable, although it would be against best practices to alter them. Therefore, if it is permissible to call Bootstrap or AngularJS a framework, there is no reason why jQuery cannot be called a framework either. 
Perhaps the best explanation of why jQuery is more of a framework than a library is the fact that as a developer, you can chose not to use any of its framework-like functionalities. You can, for example, mix a simple jQuery statement with a standard JavaScript statement on the same line. AngularJS and Bootstrap typically don't allow you to do this. Therefore, the accurate answer whether jQuery is a framework or not is "it depends whether you chose to use it as a framework or not".

Features provided by jQuery

CSS3 Selectors

When working with CSS code, selectors are patterns that can be called upon to style a particular page element.
The CSS3 selector is a new specification that will be used heavily in the future. A majority of sites are already making use of them.
You might be interested to know that one benefit of working with jQuery, is that you can also use CSS3 selectors in your production code. This just means increased support for you and more ways to create page elements and modern designs.

Helpful Utility Functions Galore

At its core, jQuery is meant to make a developer’s life easier by combining and simplifying critical syntax you would need to write out in JavaScript. It does this through an assortment of helpful utility functions that you can call upon during development.

The jQuery User Interface

Because of the power behind jQuery, it’s been used to make some pretty impressive widgets, effects, and user interface modules. These elements were useful enough that the official jQuery team decided to bundle them up and include them in the core jQuery library.
They decided early on to keep the jQuery library focused on basic use, so instead of adding the elements to the core package they created a separate one called jQuery User Interface.
The jQuery UI library includes elements like sliders, dialog boxes, date pickers, nav menu items, and accordions, all of which can be customized and themed.

jQuery Plugins

One of the added benefits of jQuery is that the team behind it has kept the core package tight and focused, remaining devoid of non-essential features. However, because of this they’ve also made sure that it’s extensible. It comes with a framework for extending the library, allowing for the use of something called plugins.
Once you create a plugin in jQuery it can be used across multiple projects. In addition, plugins can be shared with the community similar to WordPress plugins. This, in turn, means that when you start working with jQuery you have access to hundreds – if not thousands – of previously developed plugins to use on your projects. This significantly cuts down development time.
The way jQuery is structured, a lot of common functions and practices have been boiled down into a plugin. This is definitely an intended feature, not a flaw. It primarily helps you keep your syntax and final code bloat to a minimum.
Why? Because plugins can be used on a page-by-page basis instead of across an entire project. This cuts down on unnecessary bandwidth, resulting in increased loading times. It also eliminates some of the bugs or issues you might see across platforms. Finally, it’s just easier to work with and that’s that.

Advantages and disadvantages of using jQuery 

The advantages of jQuery

The main advantage of jQuery is that it is much easier than its competitors. You can add plugins easily, translating this into a substantial saving of time and effort. In fact, one of the main reasons why Resig and his team created jQuery was to buy time (in the web development world, time matters a lot).
The open source license of jQuery allows the library to always have constant and fast support, constantly publishing updates. The jQuery community is active and extremely hardworking.
Another advantage of jQuery over its competitors such as Flash and pure CSS is its excellent integration with AJAX.
  • jQuery is flexible and fast for web development
  • It comes with an MIT license and is Open Source
  • It has an excellent support community
  • It has Plugins
  • Bugs are resolved quickly
  • Excellent integration with AJAX

The disadvantages of jQuery

One of the main disadvantages of jQuery is the large number of published versions in the short time. It does not matter if you are running the latest version of jQuery, you will have to host the library yourself (and update it constantly), or download the library from Google (attractive, but can bring incompatibility problems with the code).
In addition to the problem of the versions, other disadvantages that we can mention:
  • jQuery is easy to install and learn, initially. But it’s not that easy if we compare it with CSS
  • If jQuery is improperly implemented as a Framework, the development environment can get out of control.

jQuery Selectors

jQuery selectors allow you to select and manipulate HTML element(s).
jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.
All selectors in jQuery start with the dollar sign and parentheses: $().

The element Selector

The jQuery element selector selects elements based on the element name.
You can select all <p> elements on a page like this:
$("p")
Example
When a user clicks on a button, all <p> elements will be hidden:

Example

$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
Try it Yourself »

The #id Selector

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
To find an element with a specific id, write a hash character, followed by the id of the HTML element:
$("#test")
Example
When a user clicks on a button, the element with id="test" will be hidden:

Example

$(document).ready(function(){
  $("button").click(function(){
    $("#test").hide();
  });
});
Try it Yourself »

The .class Selector

The jQuery .class selector finds elements with a specific class.
To find elements with a specific class, write a period character, followed by the name of the class:
$(".test")
Example
When a user clicks on a button, the elements with class="test" will be hidden:

Example

$(document).ready(function(){
  $("button").click(function(){
    $(".test").hide();
  });
});
Try it Yourself »

More Examples of jQuery Selectors

SyntaxDescriptionExample
$("*")Selects all elementsTry it
$(this)Selects the current HTML elementTry it
$("p.intro")Selects all <p> elements with class="intro"Try it
$("p:first")Selects the first <p> elementTry it
$("ul li:first")Selects the first <li> element of the first <ul>Try it
$("ul li:first-child")Selects the first <li> element of every <ul>Try it
$("[href]")Selects all elements with an href attributeTry it
$("a[target='_blank']")Selects all <a> elements with a target attribute value equal to "_blank"Try it
$("a[target!='_blank']")Selects all <a> elements with a target attribute value NOT equal to "_blank"Try it
$(":button")Selects all <button> elements and <input> elements of type="button"Try it
$("tr:even")Selects all even <tr> elementsTry it
$("tr:odd")Selects all odd <tr> elementsTry it

Importance of DOM

Web browsers[edit]

To render a document such as a HTML page, most web browsers use an internal model similar to the DOM. The nodes of every document are organized in a tree structure, called the DOM tree, with the topmost node named as "Document object". When an HTML page is rendered in browsers, the browser downloads the HTML into local memory and automatically parses it to display the page on screen.[8]

JavaScript[edit]

When a web page is loaded, the browser creates a Document Object Model of the page, which is an object oriented representation of an HTML document, that acts as an interface between JavaScript and the document itself and allows the creation of dynamic web pages:[9]
  • JavaScript can add, change, and remove all of the HTML elements and attributes in the page.
  • JavaScript can change all of the CSS styles in the page.
  • JavaScript can react to all the existing events in the page.
  • JavaScript can create new events within the page.

Benefits of using jQuery event handling 

If you have done any programming in JavaScript, you’ll know that working with events is fairly straightforward. Then you test your latest creation in a different browser and find that something got broken! This is a major source of frustration and jQuery aims to simplify and help us with this process.
By combining the ability to use selectors and filters to easily capture elements on the page with the event handling features of jQuery, we are given a powerful combination. Just one mouse click can be made to trigger a series of commands like adding a class, starting an animation, changing the text on the page, or sending data to a server. Often times we’ll see the blur event used to check that form fields have been properly filled before submission.
Working with events in jQuery:
  • Gives web developers a way to work with events that is much more simplified than working directly on the DOM.
  • Makes different browser implementations of events a non issue via Abstraction.
  • Provides web developers a nice time saving technique of binding and unbinding event handlers to one or many elements by using selectors and filters all at once.
Mouse EventsKeyboard EventsForm EventsDocument/Window Events
clickkeypresssubmitload
dblclickkeydownchangeresize
mouseenterkeyupfocusscroll
mouseleave blurunload

Advanced features provided by jQuery

jQuery is a lightweight, "write less, do more", JavaScript library.
The purpose of jQuery is to make it much easier to use JavaScript on your website.
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.
The jQuery library contains the following features:
  • HTML/DOM manipulation
  • CSS manipulation
  • HTML event methods
  • Effects and animations
  • AJAX
  • Utilities
Tip: In addition, jQuery has plugins for almost any task out there.

No comments:

Post a Comment

RICH WEB BASED APPLICATIONS

Term “Rich Internet Applications” (RIAs) from “Rich Web-based Applications” (RiWAs). A rich Internet application (RIA) is a Web applicati...