JQuery

Jquery works with a JavaScript Library which is loaded to execute the code. Several standard functions are already written in the linked library so we can directly use them in our code.

How the script works

We must load the Library file first. We can download the file from jquery.com. Or we can use the Content Delivery Network ( CDN) of google , Microsoft or JQuery.com and point to their link. Here is the sample code to link to Google CDN
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

Advantage of using CDN

The speed goes up as the Library can be used from the cache as several users use them frequently.

Installing JQuery

If you are not using CDN then you can download JQuery files from here. There is one basic file and above that you can download different plugins as per your requirements.

JQuery UI

Most important additional requirement will be JQuery UI ( JQuery user interface ) which is a library of different widgets like Date picker ( Calendar ) , Slider , Spinner etc.
To use JQuery UI, you must include JQuery. JQuery is the core library , JQuery UI is built on top of it.

In addition to basic JQuery library you need one more CSS file ( Style ) , known as Themes.

Download JQuery UI here

Uncompressed or Minified

Uncompressed files have long variable names, blank space and line breaks etc so it occupies more space. You need this for development of script, modifications etc. For production environment when site is lunched it is better to use minified version as it occupies less space.
Here is the files required for JQuery UI

  • JQuery
  • JQuery UI
  • JQuery UI CSS
  • Additional Plug in files
Visit JQuery UI CDN

Here is the sample code required to link to CDN
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/blitzer/jquery-ui.css" rel="stylesheet">
Keep this code above the <script>JQuery Code</script> and before the end of <BODY> tag

JQuery UI Themes

These are Thems you can configure or download

How to use Themes for JQuery UI components

Check different themes by using the dropdown list at right side of the above demo page. Once you select a theme from the list the changes will be shown and the URL of the CDN ( Content Delivery Network ) is displayed. Copy the URL and use it like this .
<link href='https://code.jquery.com/ui/1.12.1/themes/humanity/jquery-ui.css' rel='stylesheet'>

Here is a sample code to show a button and show a message associated with on Click event of the button.
<html>
<head>
<title>(Type a title for your page here)</title>
</head>
<body >
<button  id=new_one name=button1>My Button</button>

<script src="jquery-3.1.1.min.js"></script>

<script>
$(document).ready(function() {
$('#new_one').click(function(){
alert('Hi , you clicked the button');
})
})
</script>

</body>
</html>
Notice that we have used one external JavaScript file jquery-3.1.1.min.js , this is the main JQuery file which can be linked to get all libraries. You can download JQuery library file from here. Instead of downloading you can use CDN to link to this file.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

Basic Code

We will display an alert window from a button click. For showing alert window there is no need to use JQuery but with this we will learn how click event is triggered.

The element which can fire the click event can be identified by its assigned class, like this



$(document).ready(function(){
 $(".button2").click(function(){
 alert('hi');
 });
});

<input type=button value='Show Hi' class='button2'>


Here is a problem. Once the same class is assigned to different elements then all those elements will fire the click event. Check this code. Here on Click of input text box also will display the alert window. To differentiate each element of a webpage we will assign unique id to the element.


This is a div layer ( Hide Me )






<script>
$(document).ready(function(){
$("#button1").click(function(){
  $("#basic_div").toggle();
});
});
</script>
<input type=button value='Hide / Un-Hide Layer' id="button1">
<div id="basic_div" style="width: 100px; height: 100px; background: yellow;padding-left:12px;"> This is a div layer ( Hide Me )</div>


ApplicationDescription
getJSONCollecting and using Json data
getHTTP GET method of posting data
postHTTP POST method of posting data
loadload to fetch file or URL with parameters
TextBoxTextbox value and managing data
ButtonButton reading value and managing attr
CheckboxManaging Checkbox through Jquery
Radio ButtonManaging Radio buttons through Jquery
ListBoxAdding removing options from dropdown list box
functionUser Defined Function
serialize()Input data as name value pair for Form submission
Double ListBoxDependent list box for selection of Category and subcategory
Tripple ListBoxCountry > State > City : Selection of linked dropdown
Message BoxMessage layer and tooltip control
Select ElementSelect images or records by clicking
BootstrapPage Design using Bootstrap

WidgetsDescription
SliderChange input data by sliding pointer
Date PickerSelection of dates by using Calendar
draggableDraggable elements UI
droppableDroppable elements UI
Progress BarDisplaying progress with changes in value
AutocompleteSuggestion while entering text by using different sources
Dialog BoxPositioning and displaying data from table and updating records
SpinnerUse up and down arrow to increment or decrement value of a input box
Accordionfor expanding and collapsing content

Demo Scripts using jQuery
  • Tooltip Display help text above part of the text
  • Online Survey A set of questions for user to submit choice
  • Event Calendar Add and display events by selecting dates from Calendar
  • Fetch Record Collect record details from MySQL table on button click
  • Password Vaidation Check the user input in password field with message
  • Textarea Counter Display number of text inside textarea along with a progress bar
  • PHP Converter Compatible JQuery code to run inside PHP script
  • Colur Sliders Generate CSS by selecting colour of font and background
  • Edit Record Edit and update rows of data using PHP MySQL
ApplicationDescription
Form InputsText box, radio buttons, checkbox, dropdown list etc
FormLayout and design of a Form with backend script to post data

Frequently Used Code

$("#t1").css("background-color", "yellow"); // Set Background color to yellow
Redirect to different page or url
 window.location = "index.php";
Redirect after some time delay ( here 4 seconds )
setTimeout(function() { window.location = "index.php"; }, 4000);
show message for a duration
$("#msg").show();
setTimeout(function() { $("#msg").fadeOut('slow'); }, 4000);
Page Reload
location.reload();
Scrolling to the top of the page
$('html, body').animate({scrollTop: 0 }, 'slow');
Iterate through all elements of an object
$('.select_card').each(function() {
var my_id=this.id;
cards_to_upd.push(my_id); // storing in an array
});
Refresh button with Bootstrap design
<div class=text-center><a href=''><button type='button' class='btn btn-info'>Try again : Refresh</button></a></div>

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Visitors Rating
Your Rating


Google+

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net



Most Popular JQuery Scripts

1

Two dependant list boxes

2

Calendar with Date Selection

3

Data change by Slider

4

Show & Hide element
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer