JavaScript statements are executed line by line. However, with effects, the next line of code can be run even though the effect is not finished. This will cause to trigger the errors.

To prevent this, you can create a callback function.

A callback function is executed after the current effect is finished.


With Callback function:

<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").hide("slow", function(){
            alert("The paragraph is now hidden");
        });
    });
});
</script>

Without Callback function:

<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").hide(1000);
        alert("The paragraph is now hidden");
    });
});
</script>

The difference between these two function is without callback function will throw the alert box before the hide event is finished.
jQuery selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more.

All selectors in jQuery start with the dollar sign and parentheses: $().

The jQuery element selector selects elements based on the element name.

You can select all <p> elements on a page like this:
$("p") 
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

To find an element with a specific id, write a hash character, followed by the id of the HTML element:
$("#test")

Syntax Description
$("*") Selects all elements
$(this) Selects the current HTML element
$("p.intro") Selects all <p> elements with class="intro"
$("p:first") Selects the first <p> element
$("ul li:first") Selects the first <li> element of the first <ul>
$("ul li:first-child") Selects the first <li> element of every <ul>
$("[href]") Selects all elements with an href attribute
$("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"
$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"
$(":button") Selects all <button> elements and <input> elements of type="button"
$("tr:even") Selects all even <tr> elements
$("tr:odd") Selects all odd <tr> elements
This is used to restrict any jQuery code from running before the document is finished loading or document is ready.

It is good practice to wait for the document to be fully loaded and ready before working with it.

This also allows you to have your JavaScript code before the body of your document, in the head section.

Here are some examples of actions that can fail if methods are run before the document is fully loaded:
  • Trying to hide an element that is not created yet
  • Trying to get the size of an image that is not loaded yet

Alternate Syntax instead of using document ready event

 $(function(){

   // jQuery methods go here...

});
Our actual question is why we do not need to have type="text/javascript" inside the <script> tag in HTML5?

Ans: This is not required in HTML5 because javascript is the default scripting language in HTML5 and in all modern browsers!
Yesterday I got a chance to write sample build.xml for one of my colleague. He has default build.xml for his project which is written by someone based on random directories (similar to war directory structure). This build.xml is used to pack the directory sturctures and place it into the tomcat server webapp directory. In this type scenario he did not able to debugging his application from eclipse.

I advised them to create one more build.xml based on eclipse directory structure for production or uat deployment. For development purpose try to setup a tomcat server and debugging your application in eclipse without worrying about deployment. I provided that sample build.xml below. Please look it and provide your comments.

<?xml version="1.0" encoding="UTF-8"?>
<project name = "tems" basedir = "." default = "war">
  
    <property name="project-name" value="${ant.project.name}" />
    <property name="builder" value="Achappan Mahalingam" />

    <property name="war-file-name" value="${project-name}.war" />
    <property name="source-directory" value="src" />
    <property name="classes-directory" value="build/classes" />
    <property name="web-directory" value="WebContent" />
    <property name="web-xml-file" value="WebContent/WEB-INF/web.xml" />
    <property name="libs-directory" value="WebContent/WEB-INF/lib" />
    <property name="build-directory" value="build" />


    <target name = "info">
          <echo message = ""/>
          <echo message = "${project-name} Build File"/>
          <echo message = "-----------------------------------"/>
          <echo message = "Run by ${builder}"/>
       </target>

    <target name="war" depends="info">
        <mkdir dir="${build-directory}" />
        <delete file="${build-directory}/${war-file-name}" />
        <war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
            <classes dir="${classes-directory}" />
            <fileset dir="${web-directory}">
                <exclude name="WEB-INF/web.xml" />
            </fileset>
        </war>
    </target>
</project>
By using ob_start(), the page and headers aren't sent to the browser until they've loaded completely, or until we call ob_end_flush().
Wow! I got this error when i am creating a below table with FULLTEXT indices. The reason for this exception is "Full-Text Search is supported only with MyISAM Engine before MySQL version 5.6"

CREATE TABLE comment
(
    commentid int unsigned NOT NULL AUTO_INCREMENT,
    userid int unsigned NOT NULL,
    comment text NOT NULL,
    PRIMARY KEY (commentid),
    FULLTEXT KEY comment (comment)
) ;

Solution:

You specify MyISAM engine at end of the table creation.

CREATE TABLE comment
(
    commentid int unsigned NOT NULL AUTO_INCREMENT,
    userid int unsigned NOT NULL,
    comment text NOT NULL,
    PRIMARY KEY (commentid),
    FULLTEXT KEY comment (comment)
) ENGINE=MyISAM;



 
TLS is the new name for SSL. Namely, SSL protocol got to version 3.0; TLS 1.0 is "SSL 3.1". TLS versions currently defined include TLS 1.1 and 1.2. Each new version adds a few features and modifies some internal details. We sometimes say "SSL/TLS".

HTTPS is HTTP-within-SSL/TLS.

SSL (TLS) establishes a secured, bidirectional tunnel for arbitrary binary data between two hosts.

HTTP is a protocol for sending requests and receiving answers, each request and answer consisting of detailed headers and (possibly) some content. HTTP is meant to run over a bidirectional tunnel for arbitrary binary data; when that tunnel is an SSL/TLS connection, then the whole is called "HTTPS".
I tried to install  a GRUNT (which a javascript task runner to perform repetitive tasks like minification, compilation, unit testing, linting, etc...) but getting network proxy configuration settings error. So started googling to get a solution and found out the below steps to rectify this error.


C:\Users\amahalingam>npm config set proxy http://hostname:80

C:\Users\amahalingam>npm config set https-proxy http://hostname:80

C:\Users\amahalingam>npm install -g grunt-cli
C:\Users\amahalingam\AppData\Roaming\npm\grunt -> C:\Users\amahalingam\AppData\R
oaming\npm\node_modules\grunt-cli\bin\grunt
grunt-cli@0.1.13 C:\Users\amahalingam\AppData\Roaming\npm\node_modules\grunt-cli

├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.5)
└── findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)

Screenshots:

Error:














Solution:





I want to use javascript on my ongoing moodle development work. But the latest version of moodle 2.8 supporting to YUI library. Now there is no use of YUI because yahoo ceased that api due to transitioning (http://yahooeng.tumblr.com/post/96098168666/important-announcement-regarding-yui)
The soultion is that moodlers suggesting to install nodejs to use javascripts modules. So I mentioned steps which i installed on my windows 7 machine.

1. Download the latest nodejs executable file from https://nodejs.org/#download

















2. Once the installation done the files will be placed under the C://Program Files/nodesjs directory


3. Click on command prompt and test the nodejs verion to check the nodejs installed correctly.








4.  While doing nodejs installation it will also install npm.



5. To check the nodejs by script 
  Just write hello.js with the content console.log('Welcome to NodeJs!'); 
 Then from command prompt right the below command to execute it

 




6. Create a test file server.js and put this code in that file:
var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');






7. Open this address in your browser: http://127.0.0.1:1337/

Blog Archive

Total Pageviews

Popular Posts