Profile Picture
IT Made Easy
The site provides some rough IT Notes that make your life easier. The site currently has notes on HTML, CSS, Regex, OOPS, JS, JQuery, PHP, Java, ASP.NET, C#, Database, Linux, URL Rewrite, SEO, Project Management and Hosting. Please do share this site if you like.

General

  • JQuery is the most popular javascript library. It uses $ and by default can use
  • https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  1. $("#id")
  2. $(".class")
  3. $("xpath")


  • $.noconflict() relinquishes jQuery's control of the $ variable and if assigned to say $j will use $j to access jQuery.


<script type="text/javascript">

var $j = jQuery.noConflict();


$j(document).ready(function() {

// Code that uses jQuery's $ can follow here like $j("div").hide();

});


// Code that uses other library's $ can follow here.

</script>


  • Some important functions. fn() is called on an element and $.fn() on jquery and is usally low-level and not prefered
  1. css() can be used to change the style dynamically. Properties as {'color':"#000", 'display':"block"}
  2. addClass(), removeClass() and removeClass() to add, remove or toggle a class
  3. animate() gives the properties to which the animation moves. We can use easing function and speed and call back function executed after completion
  4. setInterval() and clearInterval() to repeat after an interval and setTimeout() and clearTimeout() to be excuted after timeout. There is also delay to bring in a delay between functions
  5. slideUp(), slideDown() and slideToggle() and fadeIn(), fadeOut() and fadeToggle()
  6. clone() will clone a copy which could be used later say for appending
  7. html(), text() and empty() and val()
  8. append(), prepend() -- inside block and after(), before() -- outside block
  9. ajax() will dunamically load contents, scripts and data. load() to grab html from another page given the URL


$.ajax({

url: filename,

type: "GET",

dataType: "html",

beforeSend: function () {},

success: function (data, textStatus, xhr) {},

error: function (xhr, textStatus, errorThrown) {}

});


  1. bind() and unbind() to add an event to an existing code on page load. We can use live() for adding to a dynamically added code also but delegate() preferred. on() and off() is the best method available for same
  2. preventDefault() prevents default firing action say href of a link. stopPropogation() stops eventy firing on ancestors. Events are fired in the order they are bound. stopImmediatePropogation() stops all future bound events
  3. each(fn) will execute function on each element of object
  4. data() will attach data to any DOM element. removeData() removes key and values. $.hasData inform status

jQuery.data(div, "test", { first: 16, last: "pizza!" });

$("span:first").text(jQuery.data(div, "test").first);


  1. match() extracts part of a string matching a regex whereas test() checks if it matches. contains() checks it in parent and children
  2. find(selector) gives descendents matching the selector. filter() is similar but also applies it to the parent
  3. slice() can be used to perform actions on a subset of elements prev() and next() on immediate elements in a matched set of array
  4. $.extend(target, obj1, obj2, ...) combines two or more objects into target object
  5. serialize() will create a string from a form and serializeArray() an array from form

IT Notes

by VinodSebastian



IT Downloads


Catalogue