Sunday, May 20, 2012

What I Like from Jquery

Jquery makes coding easier. Here some comparison with Javascript.

1. javascript:
    //----------------------begin-------------------------------
     var ajax;  //Creating Object
     var urlAjax = "sourceHtml.asp"
   
        if (ajax){ ajax=null; };
        ajax = new sack();   //renew AJAX Object
        ajax.method =  "POST";
        ajax.requestFile = urlAjax;    // Specifying the URL Files to be Returned               
       
        ajax.setVar("var1","val1"); //etc   
       
        ajax.onCompletion = function(){                  
            //do something, provide result;
            document.getElementByID("dest").value = result;
        };        
        ajax.runAJAX();
    //----------------------end-------------------------------
   
    jquery:
    //----------------------begin-------------------------------
    $('#dest').load("sourceHtml.asp",{"var1":"var1","etc":"etc"}, function(){
        //do something only if necessary
    });
    //----------------------end-------------------------------

2.     javascript:        document.getElementByID("dest").value = result;
    jquery:            $("#dest").val(result);

3.     javascript:
        document.getElementByID("elID").disabled = true;
        document.getElementByID("elID2").innerHTML =  "something" ;       
        document.getElementByID("elID3").value =  "something" ;   
    jquery:
        $("#elID").attr({disabled : true});
        $("#elID2").html("something") ;       
        $("#elID3").val("something") ;   

4. javascript:trim func. must be made yourself. i.e. : if(!String.trim)String.prototype.trim=function(){return this.replace(/^\s+|\s+$/,'')};
   jquery: $.trim("something");