Showing posts with label html. Show all posts
Showing posts with label html. Show all posts
Saturday, April 22, 2017
How to create a Simple calculator Using HTML and JavaScript
How to create a Simple calculator Using HTML and JavaScript
Here are the steps to create a simple calculator using HTML and JavaScript which can evaluate simple arithmetic on integer numbers. Two types of inputs text and button are used here on a table within a form element and OnClick event was used to insert button values on the screen or to evaluate the numbers.
1. At first Insert a <form> element within <body> tag.
2. Create a table using <table> .....</table> tag.
3. Insert two types of Input text and button within table data of table row using <tr><td>....</td></tr> tag.
4. Assign OnClick event for all the buttons having numbers and arithmetic operators.
5. Give blank value for Clear(C) button.
6. Use eval() function to evaluate the numbers on OnClick event of equal to sign button.
Steps to create a Simple calculator Using HTML and JavaScript
1. At first Insert a <form> element within <body> tag.
2. Create a table using <table> .....</table> tag.
3. Insert two types of Input text and button within table data of table row using <tr><td>....</td></tr> tag.
4. Assign OnClick event for all the buttons having numbers and arithmetic operators.
5. Give blank value for Clear(C) button.
6. Use eval() function to evaluate the numbers on OnClick event of equal to sign button.
Full HTML code for a Simple HTML calculator
<html>
<head></head>
<body>
<h3>Simple Calculator</h3>
<br/>
<form Name="calc">
<table border=2>
<tr>
<td colspan=4><input type=text Name="display"></td>
</tr>
<tr>
<td><input type=button value="0" OnClick="calc.display.value+=0"></td>
<td><input type=button value="1" OnClick="calc.display.value+=1"></td>
<td><input type=button value="2" OnClick="calc.display.value+=2"></td>
<td><input type=button value="+" OnClick="calc.display.value+=+"></td>
</tr>
<tr>
<td><input type=button value="3" OnClick="calc.display.value+=3"></td>
<td><input type=button value="4" OnClick="calc.display.value+=4"></td>
<td><input type=button value="5" OnClick="calc.display.value+=5"></td>
<td><input type=button value="-" OnClick="calc.display.value+=-"></td>
</tr>
<tr>
<td><input type=button value="6" OnClick="calc.display.value+=6"></td>
<td><input type=button value="7" OnClick="calc.display.value+=7"></td>
<td><input type=button value="8" OnClick="calc.display.value+=8"></td>
<td><input type=button value="x" OnClick="calc.display.value+=*"></td>
</tr>
<tr>
<td><input type=button value="9" OnClick="calc.display.value+=9"></td>
<td><input type=button value="C" OnClick="calc.display.value="></td>
<td><input type=button value="=" OnClick="calc.display.value=eval(calc.display.value)"></td>
<td><input type=button value="/" OnClick="calc.display.value+=/"></td>
</tr>
</table>
</form>
</body>
</html>
Preview of Simple HTML calculator
Related Search Terms
Simple Calculator Usnig JavaScript
Simple Calculator Usnig HTML
How to create a Calculator
Related Posts:
How to use Round, Random, Min and Max in JavaSript
How to Concatenate, Join and Sort Array in JavaScript?
How to Loop Through JavaScript Array?
How to Loop using JavaScript?
How to Show Pop Up Boxes Using JavaScript?
How to Write Conditional Statements in JavaScript?
How to Write JavaScript With HTML?
How to create Changeable Date and Time Using JavaScript?
How to Validate a HTML Form Using JavaScript?
How to create a simple form using HTML?
How to Create JavaScript Image Slideshow with LInks
How to Display Date Format in JavaScript?
How to Validate a HTML Form Using JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to Detect Visitors Browser Using JavaScript?
How to make rounded corners border using CSS
How to Create Custom CSS Template for Printing
How to create a simple form using HTML?
Go to link Download
Labels:
a,
and,
calculator,
create,
how,
html,
javascript,
simple,
to,
using
Friday, April 7, 2017
Free Html Templates Download NEW
Free Html Templates Download NEW
Free Html Templates Download (NEW) - Seeking HTML / CSS free templates that you can use to practice your skills or format converting WordPress themes? Youve come to the right place! In this roundup we have collected 7 CSS template. We know that not everyone has the time to design and code, but its definitely a growing need for visually appealing models. What if we accelerate the process?
Visually appealing design? Check!
Model-free and fresh? Check!
What are you waiting for? Read on!
We recommend for your web hosting needs!
This template is HTML / CSS do?
CSS template is a beauty to begin with, especially if they are free, the actual developers because they can use without the need to find a designer or design. There are many developers who do not have time to design, designers and do not have time to apply the Photoshop file encode them.
It goes like this:
Design made with Photoshop (Photoshop or other alternatives)
Files are converted to HTML / CSS
Developers convert HTML / CSS template to a fully functional website and has loaded
If you are in a hurry and do not want to spend much time on design and code, then you are in great luck with CSS templates!
In the market, things like that cost several hundred dollars, so we do not just help you save time explored, we also actually help you save money!
Do you want to learn how to build?
There are many free internet that you can download and try to convert PSD template, here is a tutorial with Template HTML / CSS conversion PSD detailed tracking.
Quick and easy elegant Agency Landing Page Design Adobe Photoshop
PSD to HTML Tutorial: Photoshop file code to work
Click on the image above for a demo.
It Responsive
All items listed below are not treated, they are free so we can not expect too much. But you know what? Its more fun that way, because you can try to change one or two at a site of interest.
We have established guidelines for all that follows, you just need patience and spirit!
Media requests Tutorial - Convert Burn Studio for Responsive website
Just apply what you have learned in this tutorial link above and you will soon be on your way to web Rockstar!
So, are you ready?







source
Visually appealing design? Check!
Model-free and fresh? Check!
What are you waiting for? Read on!
We recommend for your web hosting needs!
This template is HTML / CSS do?
CSS template is a beauty to begin with, especially if they are free, the actual developers because they can use without the need to find a designer or design. There are many developers who do not have time to design, designers and do not have time to apply the Photoshop file encode them.
It goes like this:
Design made with Photoshop (Photoshop or other alternatives)
Files are converted to HTML / CSS
Developers convert HTML / CSS template to a fully functional website and has loaded
If you are in a hurry and do not want to spend much time on design and code, then you are in great luck with CSS templates!
In the market, things like that cost several hundred dollars, so we do not just help you save time explored, we also actually help you save money!
Do you want to learn how to build?
There are many free internet that you can download and try to convert PSD template, here is a tutorial with Template HTML / CSS conversion PSD detailed tracking.
Quick and easy elegant Agency Landing Page Design Adobe Photoshop
PSD to HTML Tutorial: Photoshop file code to work
Click on the image above for a demo.
It Responsive
All items listed below are not treated, they are free so we can not expect too much. But you know what? Its more fun that way, because you can try to change one or two at a site of interest.
We have established guidelines for all that follows, you just need patience and spirit!
Media requests Tutorial - Convert Burn Studio for Responsive website
Just apply what you have learned in this tutorial link above and you will soon be on your way to web Rockstar!
So, are you ready?
1. Beauty Class
Demo | Download
2. Good-natured
Demo | Download
3. Rock Castle
Demo | Download
4. Wood Working
Demo | Download
5. Designa
Demo | Download
6. Folder
Demo | Download
7. BookStore
Demo | Download
Go to link Download
Thursday, March 16, 2017
How to Alter HTML Document Structure using jQuery
How to Alter HTML Document Structure using jQuery
HTML documents are represented as a tree of nodes rather than a linear sequence of characters, insertions, deletions, and replacements are not as simple as they are for strings and arrays. In jQuery there are some methods for making more complex changes to a document.
There are number of method in jQuery for inserting and replacing elements, copying elements, wrapping elements and deleting elements. For insertion and replacement of elements in HTML document, you can use the methods append(), prepend() and replacewith().
You can copy HTML elements using clone() method and wrapp the elements using wrap(), wrapInner() and wrapAll() methods. For deletion of the element you can use empty(), reomve() and unwrap() methods.
How to Insert and Replace Elements using jQuery
You can use different methods to insert and replace elements using jQuery, each of the methods takes an argument that specifies the content that is to be inserted into the document.
The inserting can be made into or before or after or in place of each selected elements. If the content to be inserted is an element that already exists in the document, it is moved from current location.
The append() method inserts an element at the end of selected element, prepend() method inserts an element at start of selected element and replaceWith() method replaces one selected element with another. For append(), prepend() and replacewith() the second argument is the current content of the element as an HTML string.
There are before() and after() methods, which can be used to insert before and after of each selected elements. For before() and after() the function is invoked with no second argument.
Here are some examples of jQuery codes for inserting and replacing elements using jQuery.
$("#clr").append("<br/>"+message);
// It adds a content at end of the #clr element
$("h1").prepend(":");
// It adds colon sign at the star of each <h1>
$("h1").before("<hr/>");
// It insert horizontal line before each <h1> element
$("h1").after("<hr/>");
// It insert horizontal line after each <h1> element$("hr").replaceWidth("<br/>");
// It replaces <hr/> elements with <br/>
$("h2").each(function(){
var h2=$(this);
h2.replaceWith("<h1>"+h2.html()+"</h1>");
});
// It replaces <h2> with <h1> keeping the content.
Similary, you can use appendTo(), prependTo(), insertAfter(), insertBefore and replaceAll() methods for the same purpose as given in the example below.
$("<br/>"+message).appendTo("#clr");
// It adds a content at end of the #clr element
$(document.createTextNode(":")).prependTo("h1");
// It adds colon sign at the star of each <h1>
$("<hr/>").insertBefore("h1");
// It insert horizontal line before each <h1> element
$("<hr/>").insertAfter("h1");
// It insert horizontal line after each <h1> element
$("<br/>").replaceAll("hr");
// It replaces <hr/> elements with <br/>
How to Copy Elements using jQuery
If you insert elements that are already part of the document, those elements will simply be moved, not copied to their new location.
If you want to copy elements to a new location instead of moving them, you must first make a copy with the clone() method. clone() makes and returns a copy of each selected element and all the descendents of those elements.
An example for copying elements using clone() method is given below.
$(document.body).append("<div id="linklist"><h1>List of Links</h1></div>");
//It appends a new div with id "linklist", to the end of the document
$("a").clone().appendTo("#linklist");
//It copy all links in the document and insert them into that new div
$("#linklist>a").after("<br/>");
//It insert <br/> elements after each link so they display on separate lines
How to Wrap Elements using jQuery
Another type of insertion into an HTML document involves wrapping a new element or elements around one or more elements. jQuery defines three wrapping functions, wrap() wraps each of the selected elements, wrapInner() wraps the contents of each selected element and wrapAll() wraps the selected elements as a group.
$("h1").wrap(document.createElement("i"));
//It produces <i><h1> .....</h1></i>
$("h1").wrapInner("<i/>");
//It produces <h1><i>........</i></h1>
$("body>p:first").wrap("<a name="lead"><div class="first"></div></a>");
// It wraps the first paragraph in one anchor and div
$("body>p:not(:first)").wrapAll("<div class="rest"></div>");
//It wraps all the other paragraps in another div
How to Delete Elements using jQuery
Along with insertions and replacements, jQuery also defines methods for deleting elements. empty() removes all children including text nodes or each of the selected elements, without altering the elements themselves. The remove() method, by contrast removes the selected elements and all their content from the document. remove() is normally invoked with no arguments and removes all elements in the jQuery object.
$("#hide").empty();
// It removes all the contents having id #hide
$("#rmv").remove();
// It removes the contents and events having id #rmv
You can use unwrap() method to perform element removal in a way that is the opposite of the wrap() or wrapAll() method. It removes the parent element of each selected element without affecting the selected elements or their siblings.
Related Posts:
How to Scroll Top or Bottom of Document Using JavaScript
How to Create Table of Contents Using JavaScript
How to Select Document Elements Using JavaScript?
How to Show Pop Up Window Using JavaScript
How to go Back Browsing History Using JavaScript
How to Click Button Using JavaScript?
How to Write JavaScript Function as URL in Hyperlink?
How to use Round, Random, Min and Max in JavaScript
How to Concatenate, Join and Sort Array in JavaScript?
How to Loop Through JavaScript Array?
How to Loop using JavaScript?
How to Show Pop Up Boxes Using JavaScript?
How to Write Conditional Statements in JavaScript?
How to Write JavaScript With HTML?
How to create Changeable Date and Time Using JavaScript?
How to Validate a HTML Form Using JavaScript?
How to create a simple form using HTML?
How to Create JavaScript Image Sideshow with Links
How to Display Date Format in JavaScript?
How to Validate a HTML Form Using JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to create Timer Using JavaScript?
Go to link Download
Monday, February 6, 2017
How to create a simple form using HTML
How to create a simple form using HTML
From is a necessary element in any website or blog. Mostly they are used to take user information for any of the purposes like logging into the user account, creating user account, allowing to subscribe malling list, allowing users to submit comments and allowing users to contact website admin, support or sales team.
Here I am going to describe "How to create a simple form using HTML" step by step with describing what is a form and what elements are used to create HTML form along with complete HTML code for a form.
A form is an area that contain form elements. You must set up a form before adding in run to the web page. To setup a form, you need to specify two important information Method and Action.
Method is a property tells the form how to transfer the data to the form processor. The value for method can be post or get In post method you are just posting information and method get means that you are just going to get another page. In almost all of the form post method is used.
Action property tells what action the form should take when the user presses the submit button. Action is the URL to which you are posting the information.
We have to use different HTML tags to create a form. The most commonly used HTML tags to create a form are listed below.
<INPUT> Tag: The most form tag is <INPUT> tag. The type of INPUT is specified with the TYPE attribute. This tag doesnt have its ending tag. The most commonly used INPUT types are listed below:
TEXT: It is used for plain type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.
Example: <INPUT TYPE="TEXT" NAME="UserName" VALUE="Username" SIZE=16 MAXLENGTH=15>
PASSWORD: It is used for password type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.
Example: <INPUT TYPE="PASSWORD" NAME="Password" VALUE="Password" SIZE=16 MAXLENGTH=15>
RADIO: It is used for single choice input system. The attributes used in this type are NAME, VALUE and CHECKED
Example: <INPUT TYPE="radio" NAME="sex" VALUE="M" CHECKED>
CHECKBOX: It is used for multiple choice input system. The attributes used in this type are NAME and VALUE.
Here I am going to describe "How to create a simple form using HTML" step by step with describing what is a form and what elements are used to create HTML form along with complete HTML code for a form.
A form is an area that contain form elements. You must set up a form before adding in run to the web page. To setup a form, you need to specify two important information Method and Action.
Method is a property tells the form how to transfer the data to the form processor. The value for method can be post or get In post method you are just posting information and method get means that you are just going to get another page. In almost all of the form post method is used.
Action property tells what action the form should take when the user presses the submit button. Action is the URL to which you are posting the information.
We have to use different HTML tags to create a form. The most commonly used HTML tags to create a form are listed below.
Different Tags for HTML Form
<INPUT> Tag: The most form tag is <INPUT> tag. The type of INPUT is specified with the TYPE attribute. This tag doesnt have its ending tag. The most commonly used INPUT types are listed below:
TEXT: It is used for plain type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.
Example: <INPUT TYPE="TEXT" NAME="UserName" VALUE="Username" SIZE=16 MAXLENGTH=15>
PASSWORD: It is used for password type of text input. The attributes used in this type are NAME, VALUE, SIZE and MAXLENGTH.
Example: <INPUT TYPE="PASSWORD" NAME="Password" VALUE="Password" SIZE=16 MAXLENGTH=15>
RADIO: It is used for single choice input system. The attributes used in this type are NAME, VALUE and CHECKED
Example: <INPUT TYPE="radio" NAME="sex" VALUE="M" CHECKED>
CHECKBOX: It is used for multiple choice input system. The attributes used in this type are NAME and VALUE.
Example: <INPUT TYPE="checkbox" NAME="MCQ" VALUE="M">
RESET: It is used to reset values entered in a form. Value is the attribute of RESET type of INPUT.
Example: <INPUT TYPE="reset" VALUE="Clear Form">
SUBMIT: It is used to submit values entered in a form. Value is the attribute of SUBMIT type of INPUT.
Example: <INPUT TYPE="submit" VALUE="Submit">
<TEXTAREA> Tag: This tag is used to specify the area of the text. This tag makes a two dimensional text area, in which viewer can type from a short sentence to many paragraphs. This tag has its ending tag and it is mostly used to create comment form or contact form. The attributes in this tag are NAME, VALUE, COLS and ROWS.
Example: <TEXTAREA NAME="Details" COLS=30 ROWS=5></TEXTAREA>
<SELECT> Tag: This tag is used to create a menu that offers visitors a list of option to choose from. This tab has also its ending tag. The attributes in this tag are NAME, MULTIPLE and SIZE.
Example: <SELECT NAME="Menu" MULTIPLE SIZE=3><OPTION>.....</SELECT>
<OPTION> Tag: It is the mini tag of <SELECT> tag. This tag is used to define the options to choose from the drop-down list. SELECTED is the attribute of <OPTION> Tag.
Example: <SELECT NAME="Menu" MULTIPLE SIZE=3><OPTION SELECTED>Programming Guide<OPTION>MCQs</SELECT>
Here is a sample form to allow users to create user and subscribe for the topics they want along with complete HTML code and its output.
HTML Code to Create a Simple Form
<html>
<head><title>Subscription Form</title></head>
<body>
<h1 align=center>Subscription Form</h1>
<br/>
<FORM METHOD=POST ACTION=mailto:siteforinfotech@gmail.com>
<DIV>First Name:<INPUT TYPE=text NAME=fname VALUE=Enter First Name SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Last Name:<INPUT TYPE=text NAME=lname VALUE=Enter Last Name SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Password:<INPUT TYPE=password NAME=password SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Retype Password:<INPUT TYPE=password NAME=rpassword SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Email:<INPUT TYPE=text NAME=email VALUE=Enter Your Email SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Sex:<INPUT TYPE=radio NAME=sex VALUE=M>Male<INPUT TYPE=radio NAME=sex VALUE=F>Female</DIV><br/>
<DIV>Write About You:<TEXTAREA NAME=about COLS=30 ROWS=4></TEXTAREA></DIV><br/>
<DIV>Your Academic Level: <SELECT><OPTION>High School<OPTION>College Degree<OPTION>University Degree</SELECT></DIV><br/>
<DIV>Select your Topic to Subscribe:<br/><INPUT TYPE=checkbox NAME=topic VALUE=M>Multiple Choice Questions<br/>
<INPUT TYPE=checkbox NAME=topic VALUE=T>IT Tutorials<br/>
<INPUT TYPE=checkbox NAME=topic VALUE=P>Programming Guide<br/><br/>
<INPUT TYPE=submit VALUE=Submit><INPUT TYPE=reset VALUE=Reset>
</FORM>
</body>
</html>
Preview of the above HTML Code
Subscription Form
Here I have posted the HTML codes for sample only. You can customize this form according to your requirement. You can extract and use any element to create your own form.
Related Posts:
How To Create Simple Image Slideshow Using JavaScript ?
Image Slideshow with Navigation Buttons Using JavaScript
How to Create JavaScript Image Slideshow with LInks
How to Display Date Format in JavaScript?
How to Create a Digital Clock in JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to Detect Visitors Browser Using JavaScript?
How to make rounded corners border using CSS
How to Create Custom CSS Template for Printing
How to Create Responsive Website or Blogger Template
Go to link Download
Monday, December 19, 2016
How to Validate a HTML Form Using JavaScript
How to Validate a HTML Form Using JavaScript
In the previous post, I have described about "How to create a simple form using HTML" step by step with describing what is a form and what elements are used to create HTML form along with complete HTML code for a form. In this post I am going to describe about to Validate a this HTML Form Using JavaScript.
You can validate a HTML Form Using JavaScript for the following circumstances.
Here in this post I am going to describe you, "How to Validate Required Fields using JavaScript.
This JavaScript Function below checks if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If the value is entered the function returns true.
You can validate a HTML Form Using JavaScript for the following circumstances.
- Whether or not the user left required fields empty
- Whether or not the user entered a valid e-mail address
- Whether or not the user entered a valid date
- Whether or not the user entered text in numeric field or entered number in text field
Here in this post I am going to describe you, "How to Validate Required Fields using JavaScript.
Validating Required Field using JavaScript
This JavaScript Function below checks if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If the value is entered the function returns true.
function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}
Complete JavaScript Code with HTML for Validating Required Field
Here are the complete JavaScript codes along with complete HTML codes uses with the JavaScript Functions given below.
<html>
<head><title>Subscription Form</title>
<script type="text/javascript">
function validate_required(field, alerttxt)
{
with(field)
{
if (value===null||value==="")
{alert(alerttxt); return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with(thisform)
{
if (validate_required(fname, "First name must be filled out!")===false)
{fname.foucus(); return false;}
if (validate_required(lname, "Last name must be filled out!")===false)
{lname.foucus(); return false;}
if (validate_required(password, "Password must be filled out!")===false)
{password.foucus(); return false;}
if (validate_required(rpassword, "Retype Password must be filled out!")===false)
{rpassword.foucus(); return false;}
}
}
</script>
</head>
<body>
<FORM METHOD=GET ONSUBMIT="return validate_form(this);" ACTION="http://www.siteforinfotech.com/p/about-us.html">
<DIV>First Name:<INPUT TYPE=text NAME=fname VALUE=Enter First Name SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Last Name:<INPUT TYPE=text NAME=lname VALUE=Enter Last Name SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Password:<INPUT TYPE=password NAME=password SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Retype Password:<INPUT TYPE=password NAME=rpassword SIZE=30 MAXLENGTH=25></DIV><br/>
<DIV>Email:<INPUT TYPE=text NAME=email VALUE=Enter Your Email SIZE=30 MAXLENGTH=25></DIV><br/>
<br/>
<INPUT TYPE=submit VALUE=Submit><INPUT TYPE=reset VALUE=Reset>
</FORM>
</body>
</html>
Preview of the above HTML Code
Here I have posted this JavaScript and HTML codes for sample only. You can write validation JavaScript to validate other fields for other circumstances.
Related Posts:
How To Create Simple Image Slideshow Using JavaScript ?
Image Slideshow with Navigation Buttons Using JavaScript
How to Create JavaScript Image Slideshow with LInks
How to Display Date Format in JavaScript?
How to Create a Digital Clock in JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to Detect Visitors Browser Using JavaScript?
How to make rounded corners border using CSS
How to Create Custom CSS Template for Printing
How to create a simple form using HTML?
Go to link Download
Monday, December 5, 2016
How to Use jQuery With HTML
How to Use jQuery With HTML
jQuery() is a single global function defined by jQuery library. This function is so frequently used that the library also defines the global symbol $ as a shortcut for it.
This single global function with two names is the central query function for jQuery. For example, if you need to ask for the set of all <div> elements in a document, write the following code.
var divs=$("div");
The value returned by the jQuery() function represents a set of zero or more DOM elements is known as a jQuery object. jQuery objects define many methods for operating on the sets of elements they represent.
How to Obtain jQuery
jQuery library is free software. You can download if from http://www.jquery.com. Once you have download the code, you can include it in your web pages with a <script> element as given below.
<script src="jquery-1.11.2.min.js"></script>
Here the "min" in the filename indicates that this is the minimized version of the library, with unnecessary comments and whitespace removed, and internal identifiers replaced with shorter ones.
And another way to use jQuery in your web application is to allow a Content Distribution Network (CDN) to serve it using a URL like one of these.
Google CDN
https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
Microsoft CDN
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.3.min.js
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js
jQuery CDN
http://code.jquery.com/jquery-2.1.3.min.js
http://code.jquery.com/jquery-1.11.2.min.js
http://code.jquery.com/jquery-1.11.2.min.js
If you use Google CDN, you can use "1.11" to get the latest release in the 1.11.x series, or just "1" to get the most current release less than 2.0.
The major advantage of loading jQuery from well-known URLs like these is that, because of jQuerys popularity, visitors to your website will likely already have a copy of the library in the browsers cache and no download will be necessary.
How to Use jQuery() Function
The jQuery() function is the most important one in the jQuery library. It is heavily overloaded, however, and there are four different ways you can invoke it.
The first, and the most common way to invoke $() is to pass a CSS selector to it. Which returns the set of elements from the current document that match the selector as given in the example below.
var id=$("#id");
var class=$(".class");And the another way to invoke $() is to pass it an Element or Document or Window object. It simply wraps the element, document or window in a jQuery object and returns that object. Doing this allows you to use jQuery methods to manipulate the element rather than using raw DOM methods. For example you can call $(document) or $(this) to pass document or current element.
The third way to invoke $() is to pass it a string of HTML text. When you do this, jQuery creates the HTML element or elements described by that text and then returns a jQuery object representing those elements.
When invoked in this way, $() accepts an optional second argument. You can pass a document object to specify the document with which the elements are to be associated. If you do this, the object properties are assumed to specify the names and values of HTML attributes to be set on the object.
Here is an example, where three arguments are used to set the url, css of the image and the click event on the image.
var img=$("<img />"),
{src:url,
css:{borderWidth:5},
click:handleClick
});And the fourth way to invoke $() is to pass a function to it. If you do this, the function you pass will be invoked when the document has been loaded and the DOM is ready to be manipulated. For example here is a jQuery version of onLoad() function which is invoked when the document has loaded.
$(function(){
// jQuery code
});
Read Next:How to Get and Set Element Attributes using jQuery
Related Search Terms
How to use jQuery in HTML
How to Obtain jQuery
Related Posts:
How to Scroll Top or Bottom of Document Using JavaScript
How to Create Table of Contents Using JavaScript
How to Select Document Elements Using JavaScript?
How to Show Pop Up Window Using JavaScript
How to go Back Browsing History Using JavaScript
How to Click Button Using JavaScript?
How to Write JavaScript Function as URL in Hyperlink?
How to use Round, Random, Min and Max in JavaScript
How to Concatenate, Join and Sort Array in JavaScript?
How to Loop Through JavaScript Array?
How to Loop using JavaScript?
How to Show Pop Up Boxes Using JavaScript?
How to Write Conditional Statements in JavaScript?
How to Write JavaScript With HTML?
How to create Changeable Date and Time Using JavaScript?
How to Validate a HTML Form Using JavaScript?
How to create a simple form using HTML?
How to Create JavaScript Image Sideshow with Links
How to Display Date Format in JavaScript?
How to Validate a HTML Form Using JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to create Timer Using JavaScript?
Go to link Download
Monday, November 7, 2016
How to Write JavaScript With HTML
How to Write JavaScript With HTML
JavaScript is the most popular scripting language in the web to improve the design, validate forms, detect browsers, create cookies and many more client side functionalities and works in all major browsers, such as Internet Explorer, Mozilla Firefox, Google Chrome, Netscape, Opera and many more.
It is a lightweight programming language consisting of lines of executable computer code and usually embedded directly into HTML pages.
To write JavaScript with HTML page, you have to use the <script> tag along with the type attribute to define the scripting language. So the <script type="text/javascript"> and </script> tells where the javascript starts and end.
There are different ways to write JavaScript with HTML, which are as follows.
You can write <script> tag in the head section as follows.
<html>
<head>
<script type="text/javascript">
javascript codes are written here
</script>
</head>
<body>
</body>
</html>
You can write <script> tag in the body section as follows.
<html>
<head>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>
<html>
<head>
<script type="text/javascript">
It is a lightweight programming language consisting of lines of executable computer code and usually embedded directly into HTML pages.
To write JavaScript with HTML page, you have to use the <script> tag along with the type attribute to define the scripting language. So the <script type="text/javascript"> and </script> tells where the javascript starts and end.
Different Ways to Write JavaScript with HTML
There are different ways to write JavaScript with HTML, which are as follows.
Scripts in the HEAD Section
When scripts are placed in head section, they needs to be executed when they are called, or when an event is triggered and it will ensure that the script is loaded before anyone uses it.You can write <script> tag in the head section as follows.
<html>
<head>
<script type="text/javascript">
javascript codes are written here
</script>
</head>
<body>
</body>
</html>
Scripts in the BODY section
As in the head section, you can also place JavaScript codes in the body section using <script> tag and it will be executed when the page loads.You can write <script> tag in the body section as follows.
<html>
<head>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>
Scripts in both the HEAD and BODY section
You can write <script> tag in both the head and body section as follows.<html>
<head>
<script type="text/javascript">
javascript codes are written here
</script>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>
If you needs to write same JavaScript code on several pages, you can write it on separate external page with a .js file extension and can link it to the HTML file.
You can link external JavaScript file to HTML file as follows.
<html>
<head>
<script src="javascript.js">
</script>
</head>
<body>
</body>
</html>
</script>
</head>
<body>
<script type="text/javascript">
javascript codes are written here
</script>
</body>
</html>
Scripts Using an External JavaScript File
If you needs to write same JavaScript code on several pages, you can write it on separate external page with a .js file extension and can link it to the HTML file.You can link external JavaScript file to HTML file as follows.
<html>
<head>
<script src="javascript.js">
</script>
</head>
<body>
</body>
</html>
Read Next: How to Write Conditional Statements in JavaScript?
Related Search Terms
How to link JavaScript with HTML
How to use JavaScript on HTML
Related Posts:
How To Create Simple Image Slideshow Using JavaScript ?
Image Slideshow with Navigation Buttons Using JavaScript
How to create Changeable Date and Time Using JavaScript?
How to Create JavaScript Image Slideshow with LInks
How to Display Date Format in JavaScript?
How to Validate a HTML Form Using JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to Detect Visitors Browser Using JavaScript?
How to make rounded corners border using CSS
How to Create Custom CSS Template for Printing
How to create a simple form using HTML?
Go to link Download
Subscribe to:
Comments (Atom)