THE jQuery, without a shadow of a doubt, revolutionized the way we write codes in the Javascript language. Not only because of its ease, but also because of the wide variety of resources that we can have when using this excellent JavaScript framework, ranging from simple DOM edits to Ajax requests and event handling.
Used by most web developers today, this framework has been constantly updated and improved, but one of the things that is most impressive is the size of the framework, which together with GZip reaches a size of less than 30KB. That's right, you can enjoy all these features and it will weigh your project in just 30KB. And to make things even better, jQuery is now hosted by Google and its “super cache”.
Including the framework in the project
To include this library in your project, there are 3 different ways:
- Download the file and host it locally on your server.
- Use the Google API for library loading:
where “1.8.3” is the version of the framework you want to use. If you enter '1' in this parameter, the Google API will always return the most recent version.<script src="http://www.google.com/jsapi?key=sua_chave_aqui" type="text/javascript"</script> <script type="text/javascript">google.load('jquery','1.8.3');</script> - Direct API call (My favorite):
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
Introduction to Selectors
One of the great attractions of the jQuery development team was thinking about the practicality and ease of its selectors. Selectors are ways to group and select multiple objects via Javascript and apply actions and events to that group of elements or a specific element. This grouping can be carried out using the #id, the object's class, a CSS characteristic, the object's name, an HTML attribute on the page, child elements of a parent element and much more!
Examples:
– Selecting all
tags from
$("#teste p").css("color", "#fffffff");– Retrieve all elements whose class=’testeClasse’ and add the class “outraClasse” to the elements.
$(".testeClasse").addClass("outraClasse");– Retrieve all link elements () that do not have the “product” class
$("a:not('.produto')")– Retrieve all link elements () that open external links (target=’_blank’)
$("a[target='_blank']")– Retrieve all link elements () that open links that contain “facebook.com”
$("a[href*='facebook.com']")– Retrieve the first, last and 9th link element () of the page
$("a:first");
$("a:last");
$("a:nth(8)"); // Índice inicia em 0
See more about all selectors by accessing this link.
Events
Another great revolution that jQuery brought to Web development was the way we manage events in our applications. Before, we had to “contaminate” our HTML pages with onclick, onchage, onblur, etc. codes. which goes completely against the layered development pattern, separating business rules from the interface (Yes, you can program object-oriented and using MVC in Javascript).
That has now changed! With jQuery, we can completely isolate HTML pages and Javascript codes.
Examples:
– Printing on the screen the selected value of a
$("#id_aluno").change(function() {
var valor_selecionado = $(this).val();
alert(valor_selecionado);
});
– Validating a field with id = “nome” before sending the form whose id is “frmCadastroAluno”
$("#frmCadastroAluno").submit(function() {
if ($("#nome").val().length == 0) {
alert("Por favor, preencha o campo Nome");
return false;
}
});
– Printing the URL of a link () when clicking and not following the link:
$("a").click(function (e) {
e.preventDefault();
var elemento = $(this);
var link = elemento.attr("href");
alert(link);
});See all events accessing this link.
Plugins
Another great innovation that this project provided us was the creation and use of plugins for code reuse. If you search on Google, you will find thousands of plugins, which perform the most varied functions in conjunction with jQuery. Image galleries, visual effects, new features, usability improvements, interface improvements…
Below is my list of essential plugins
- Tablesorter – Improvements and enhancements to tables, such as ordering.
- TipTip – New interface for help balloons, more elegant and user-friendly.
- SexyAlertBox – A more modern and stylish way to display alert messages.
- Easing – A plugin that provides various effects for your applications.
- jCarousel – One of the best plugins for making an image carousel.
- Colorbox – A super light and elegant photo gallery, with 5 different themes.
- cycle – The best and most complete plugin to create an animated banner.
- Uploadify – The best solution for sending multiple uploads. Very customizable and adapts well to any project or need.
- MaskMoney – Plugin that allows you to create currency-type fields easily and without complications.
- InputValue – Filter which types of values will be accepted by your form fields with this plugin.
- MaskedInput – Create a mask for the most diverse fields in your form, such as telephone, email, CPF, etc.
- BlockUI – “Lock” your user interface while a process runs in the background or to give focus to another window.
- MeioMask – Brazilian plugin that performs different types of masks and validations on forms.
- jQuery SWFObject – Insert Flash animations into your applications dynamically and without causing HTML validation problems in the W3C validator.
Comentários (0)
Carregando comentários…