JavaScript Frameworks/Libraries

http://www.w3schools.com/js/js_libraries.asp

JavaScript Frameworks (Libraries)

Advanced JavaScript programming (especially the complex handling of browser differences), can often be very difficult and time-consuming to work with.

To deal with these difficulties, a lot of JavaScript (helper) libraries have been developed.

These JavaScript libraries are often called JavaScript frameworks.

In this tutorial, we will take a look at some of the most popular JavaScript frameworks:

  • jQuery
  • Prototype
  • MooTools

All of these frameworks have functions for common JavaScript tasks like animations, DOM manipulation, and Ajax handling.

In this tutorial we will teach you how start using them, to make JavaScript programming easier, safer, and much more exciting.


jQuery

jQuery is the most popular JavaScript framework on the Internet today.

It uses CSS selectors to access and manipulate HTML elements (DOM Objects) on a web page.

jQuery also provides a companion UI (user interface) framework and numerous other plug-ins.

Many of the largest companies on the Web use jQuery:

  • Google
  • Microsoft
  • IBM
  • Netflix

You will find an excellent jQuery Tutorial here at W3Schools.


Prototype

Prototype is a JavaScript library that provides a simple API to perform common web tasks.

API is short for Application Programming Interface. It is a library of properties and methods for manipulating the HTML DOM.

Prototype enhances JavaScript by providing classes and inheritance.


MooTools

MooTools is also a framework that offers an API to make common JavaScript programming easier.

MooTools also includes some lightweight effects and animation functions.


Other Frameworks

Here are some other frameworks not covered in this short overview:

YUI – The Yahoo! User Interface Framework is a large library that covers a lot of functions, from simple JavaScript utilities to complete internet widgets.

Ext JS – Customizable widgets for building rich Internet applications.

Dojo – A toolkit designed around packages for DOM manipulation, events, widgets, and more.

script.aculo.us – Open-source JavaScript framework for visual effects and interface behaviors.

UIZE – Widgets, AJAX, DOM, templates, and more.


CDN – Content Delivery Networks

You always want your web pages to be as fast as possible. You want to keep the size of your pages as small as possible, and you want the browser to cache as much as possible.

If many different web sites use the same JavaScript framework, it makes sense to host the framework library in a common location for every web page to share.

A CDN (Content Delivery Network) solves this. A CDN is a network of servers containing shared code libraries.

Google provides a free CDN for a number of JavaScript libraries, including:

  • jQuery
  • Prototype
  • MooTools
  • Dojo
  • Yahoo! YUI

To use a JavaScript framework library in your web pages, just include the library in a <script> tag:


Using Frameworks

Before you decide to use a JavaScript framework for your web pages, it might be a good idea to test the framework first.

JavaScript frameworks are very easy to test. You don’t have to install them on your computer, and there are no setup programs.

Normally you just have to reference a library file from your web page.

Advertisements

show, hide control with javascript by style.display and style.visibility

<html>
<header>
<title>javascript</title>
<script type=”text/javascript”>
function div_visible(id,visible_status)
{
var div=document.getElementById(id);
if(visible_status)
{
div.style.display=””;
}
else
{
div.style.display=”none”;
}
}
function image_visible(id,visible_status)
{
var image=document.getElementById(id);
if(visible_status)
{
image.style.visibility=”visible”;
}
else
{
image.style.visibility=”hidden”;
}
}
</script>
</header>
<body>
<div>
<input type=”button” value=”show div” onclick=”div_visible(‘theDiv’,true);”/>
<input type=”button” value=”hide div” onclick=”div_visible(‘theDiv’,false);”/>
<input type=”button” value=”show image” onclick=”div_visible(‘theImage’,true);”/>
<input type=”button” value=”hide image” onclick=”div_visible(‘theImage’,false);”/>
<input type=”button” value=”show image” onclick=”image_visible(‘theImage’,true);”/>
<input type=”button” value=”hide image” onclick=”image_visible(‘theImage’,false);”/>
<div id=”theDiv”>
</div>
</div>
</body>
</html>

<html>

<header>

<title>javascript</title>

<script type=”text/javascript”>

function div_visible(id,visible_status)

{

var div=document.getElementById(id);

if(visible_status)

{

div.style.display=””;

}

else

{

div.style.display=”none”;

}

}

function image_visible(id,visible_status)

{

var image=document.getElementById(id);

if(visible_status)

{

image.style.visibility=”visible”;

}

else

{

image.style.visibility=”hidden”;

}

}

</script>

</header>

<body>

<div>

<input type=”button” value=”show div” onclick=”div_visible(‘theDiv’,true);”/>

<input type=”button” value=”hide div” onclick=”div_visible(‘theDiv’,false);”/>

<input type=”button” value=”show image” onclick=”div_visible(‘theImage’,true);”/>

<input type=”button” value=”hide image” onclick=”div_visible(‘theImage’,false);”/>

<input type=”button” value=”show image” onclick=”image_visible(‘theImage’,true);”/>

<input type=”button” value=”hide image” onclick=”image_visible(‘theImage’,false);”/>

<div id=”theDiv”>

<img id=”theImage” src=”http://vnexpress.net/Files/Subject/3B/A1/41/40/250.jpg”/&gt;

</div>

</div>

</body>

</html>

Change href, target, text of an anchor tag using Javascript

http://techjunk.websewak.com/change-href-target-text-of-an-anchor-tag-using-javascript/

Code (javascript)

<html>
<head>
<script type=“text/javascript”>
function changeLink()
{

        document.getElementById(‘myLink’).innerHTML=“WebSewak”;
        document.getElementById(‘myLink’).href=http://www.websewak.com&#8221;;

        document.getElementById(‘myLink’).target=“_blank”;
}

</script>
</head>
<body>

<a id=“myLink” href=http://www.yah.in&#8221;>Yah.in Collection</a>

<input type=“button” onclick=“changeLink()” value=“Change link”>

</body>
</html>
 

Javascript- Slideshow Image

var image1=new Image()
image1.src=”http://hunghv/PublishingImages/newsarticleimage.jpg&#8221;
(script type=”text/javascript”)
var image2=new Image()
image2.src=”http://hunghv/Th%20vin%20nh/_t/setup_4_JPG.jpg&#8221;
var image3=new Image()
image3.src=”http://hunghv/_layouts/images/titlegraphic.gif&#8221;
(/script)

(img src=”firstcar.gif” width=”320″ /)

(script type=”text/javascript”)
var step=1
function slideit(){
if (!document.images)
return
document.images.slide.src=eval(“image”+step+”.src”)
if (step<3)
step++;
else
step=1
setTimeout(“slideit()”,5000)
}
slideit()
(/script)

Add event to object in javascript

// Find all the ‘li’ elements, to attach the event handlers to them

var li = document.getElementsByTagName(“li”);
for ( var i = 0; i < li.length; i++ ) {
// Attach a mouseover event handler to the ‘li’ element,
// which changes the ‘li’s background to blue.
li[i].onmouseover = function() {
this.style.backgroundColor = ‘blue’;
};
// Attach a mouseout event handler to the ‘li’ element
// which changes the ‘li’ background back to its default white
li[i].onmouseout = function() {
this.style.backgroundColor = ‘white’;
};
}