Thursday, June 1, 2017

jQuery Event


   πŸ’₯ All the different visitor's actions that a web page can respond to are called events.

  πŸ’₯  An event represents the precise moment when something happens.
Examples:
  • moving a mouse over an element
            πŸ’§<script>
$(document).ready(function(){
    $("p").on({
        mouseenter: function(){
            $(this).css("background-color", "lightgray");
        }, 
        mouseleave: function(){
            $(this).css("background-color", "lightblue");
        },
        click: function(){
            $(this).css("background-color", "yellow");
        } 
    });
});
</script>

  • selecting a radio button
           πŸ’§<script>
$(document).ready(function(){
    $("input").keypress(function(){
        $(this).hide();
    });
});
</script>

  • clicking on an element

  •        πŸ’§<script>
    $(document).ready(function(){
        $("p").on("click", function(){
            $(this).hide();
        });
    });
    </script>

jQuery




πŸ’₯ jQuery is a JavaScript Library.

πŸ’₯  jQuery greatly simplifies JavaScript programming.  
πŸ’₯ The purpose of jQuery is to make it much easier to use JavaScript on your website.

πŸ’¦ jQuery Syntax

Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)
 
 

πŸ’¦ jQuery Selectors

      πŸ‘¦The element Selector

              You can select all <p> elements on a page like this:
$("p") 
 
 
    πŸ‘¦The  #id selector

      An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
$("#test") 
 
     πŸ‘¦ The . class selector

     To find elements with a specific class, write a period character, followed by the name of the class:
$(".test") 
 
 

 



  

Friday, May 26, 2017

JavaScript Function,Object

πŸ’₯A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ()

The code to be executed, by the function, is placed inside curly brackets: {}

πŸ‘Šfunction name(parameter1, parameter2, parameter3) {
    code to be executed
}


πŸ’₯ We can use function different ways

 πŸ‘Š<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World!";
}
myFunction();


 πŸ‘Š<script>
function myFunction(name) {
    return "Hello " + name;
}
document.getElementById("demo").innerHTML = myFunction("John");
</script>


πŸ’₯OBJECT


πŸ‘Š <script>
var person = {
    firstName : "John",
    lastName  : "Doe",
    age       : 50,
    eyeColor  : "blue"
};

document.getElementById("demo").innerHTML =
person.firstName + " is " + person.age + " years old.";
</script>

 
output  John is 50 years old

 πŸ‘Š<script>
var person = {
    firstName: "John",
    lastName : "Doe",
    id       : 5566,
    fullName : function() {
       return this.firstName + " " + this.lastName;
    }
};

document.getElementById("demo").innerHTML = person.fullName();
</script>


output  John Doe

Java Script Data Type

 πŸ’₯JavaScript variables can hold many data types: 

  • numbers 
var length = 16;
  • strings
 var lastName = "Johnson";    
  • objects  
 var x = {firstName:"John", lastName:"Doe"};
  • boolean
<script>
document.getElementById("demo").innerHTML =
typeof true + "<br>" +
typeof false;
</script>

  • null
 <script>
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
var person = null;
document.getElementById("demo").innerHTML = typeof person;
</script>


out put object

  • undefined 
 <script>
var person;
document.getElementById("demo").innerHTML =
person + "<br>" + typeof person;
</script>
 
  πŸ’₯JavaScript evaluates expressions from left to right. Different sequences can produce different results


  πŸ‘Š<script>
var x = "Volvo" + 16 + 4;
document.getElementById("demo").innerHTML = x;
</script>



 output  volvo164


 πŸ‘Š <script>
var x = 16 + 4 + "Volvo";
document.getElementById("demo").innerHTML = x;
</script>


output 20Volvo

  πŸ’₯We can use single or double invert comma  for string &  use quotes inside a string
 
 πŸ‘Š<script>
var carName1 = "Volvo XC60";
var carName2 = 'Volvo XC60';
var answer1 = "It's alright";
var answer2 = "He is called 'Johnny'";
var answer3 = 'He is called "Johnny"';

document.getElementById("demo").innerHTML =
carName1 + "<br>" +
carName2 + "<br>" +
answer1 + "<br>" +
answer2 + "<br>" +
answer3;
</script>


output  

Volvo XC60
Volvo XC60
It's alright
He is called 'Johnny'
He is called "Johnny"

             

JavaScript Arithmetic


 πŸ’₯The addition operator (+) adds numbers

πŸ‘Š<script>
var x = 10;
var y = 2;
var z = x + y;
document.getElementById("demo").innerHTML = z;
</script>


output 12 

 πŸ’₯The subtraction operator (-) subtracts numbers

 πŸ‘Š<script>
var x = 5;
var y = 2;
var z = x - y;
document.getElementById("demo").innerHTML = z
</script>


output 3

  πŸ’₯The multiplication operator (*) multiplies numbers

  πŸ‘Š<script>
var x = 5;
var y = 6;
var z = x * y;
document.getElementById("demo").innerHTML = z; 

</script>
                                  OR
 output 30<script>
var x = 10;
x *= 5;
document.getElementById("demo").innerHTML = x;
</script>

output 50


  πŸ’₯The modular operator (%) returns the division remainder.

πŸ‘Š <script>
var x = 5;
var y = 2;
var z = x % y;
document.getElementById("demo").innerHTML = z;
</script>

                                      
output 1

                                    OR
<script>
var x = 10;
x %= 5;
document.getElementById("demo").innerHTML = x;
</script>

output 0


πŸ’₯The increment operator (++) increments numbers

  πŸ‘Š<script>
var x = 5;
x++;
var z = x;
document.getElementById("demo").innerHTML = z;
</script>


output 6

  πŸ’₯Operator precedence describes the order in which operations are performed in an arithmetic expression.

  πŸ‘Š<script>
document.getElementById("demo").innerHTML = 100 + 50 * 3;
</script>


output  250


πŸ‘Š <script>
document.getElementById("demo").innerHTML = (100 + 50) * 3;
</script>


output 450



Java Script variable


     πŸ’₯Creating a variable in JavaScript is called "declaring" a variable.

  • You declare a JavaScript variable with the var keyword
  • Start the statement with var and separate the variables by comma
  •   you can do arithmetic with JavaScript variables

      πŸ‘Š <script>
var x = 2 + 3 + "5"
document.getElementById("demo").innerHTML = x;
</script>


output: 55 

    πŸ‘Š<script>
var x = 5 + 2 + 3;
document.getElementById("demo").innerHTML = x;
</script>


output: 10


    πŸ‘Š<script>
x = "5" + 2 + 3;
document.getElementById("demo").innerHTML = x;
</script>


output: 523

   πŸ‘Š <script>
var x = 5;
var y = 2;
var z = x * y;
document.getElementById("demo").innerHTML = z;
</script>


outtput 10




Tuesday, May 23, 2017

Javascript

πŸ’₯ JAVASCRIPT

 

      JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client-side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities.


πŸ’₯why use JavaScript

JavaScript is one of the 3 languages all web developers must learn:
   1. HTML to define the content of web pages
   2. CSS to specify the layout of web pages
   3. JavaScript to program the behavior of web pages


πŸ’₯Where to use Java Script

    πŸ’’ In HTML, JavaScript code must be inserted between <script> and </script> tags.
    
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>



 
  πŸ’’Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.

     
       <head> <script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
       </head>

 <body>
<p id="demo"></p>
<button type="button" onclick="myFunction()">Try it</button>

<script>
function myFunction() {
   document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>

</body>

  

πŸ’’ Scripts can also be placed in external files
         external files has some advantages:
  • It separates HTML and code
  • It makes HTML and JavaScript easier to read and maintain
  • Cached JavaScript files can speed up page loads
<script src="myScript1.js"></script> <script src="myScript2.js"></script>
πŸ’₯JavaScript can "display" data in different ways
  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using document.write().
  • Writing into an alert box, using window.alert().
  • Writing into the browser console, using console.log().
 πŸ’₯JavaScript syntax is the set of rules, how JavaScript programs are constructed.
   πŸ’₯JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.

   πŸ’₯The JavaScript syntax defines two types of values: Fixed values and variable values.
Fixed values are called literals. Variable values are called variables.

  πŸ’₯ Java Script Variables

variables are used to store data values.
JavaScript uses the var keyword to declare variables.
An equal sign is used to assign values to variables.
  Eg:
   <script>
var x;
x = 6;
document.getElementById("demo").innerHTML = x;
</script>



πŸ’’ The values can be of various types, such as numbers and strings.
Eg:  "John" + " " + "Doe", evaluates to "John Doe"

πŸ’₯Java Script Comments

Code after double slashes // or between /* and */ is treated as a comment

 

πŸ’₯JavaScript is Case Sensitive

      All JavaScript identifiers are case sensitive. 
The variables lastName and lastname, are two different variables.
Eg: 

<script>
var lastname, lastName;
lastName = "Doe";
lastname = "Peterson";
document.getElementById("demo").innerHTML = lastName;
</script>


out put: Doe 


 πŸ’₯Java Script is Camel Case

 Hyphens

     first-name, last-name, master-card, inter-city.

πŸ‘± Hyphens are not allowed in JavaScript. It is reserved for subtractions.

Underscore
first_name, last_name, master_card, inter_city.

Upper Camel Case
FirstName, LastName, MasterCard, InterCity.

Lower Camel Case
 use camel case that starts with a lowercase letter
firstName, lastName, masterCard, interCity.