Search This Blog

Previous blogs

  • ()
Theme images by Storman. Powered by Blogger.

Translate

Download the latest IPL 2018 app for live scores and schedule

Download the latest IPL 2018 App for live scores, Schedule, Teams, News and Dream 11. You can download this App by this 3 links. 1. ...

Featured Posts

Download the latest IPL 2018 app for live scores and schedule

- No comments

Download the latest IPL 2018 App for live scores, Schedule, Teams, News and Dream 11.

You can download this App by this 3 links.

1. https://www.file-upload.com/6kgdh4hk08fp

2. goo.gl/dfT6Xt (Google drive)

3. goo.gl/GkWJDD (Aptoid)

This is the best app for IPL 2018.

Screenshots






IPL 2018
IPL 2018 APP
IPL 2018 LIVE SCORE
IPL LIVE SCORES
IPL 11 LIVE SCORES
IPL 2018 TEAMS
IPL 2018 LIVE SCORES AND MORE
IPL 2018 TEAMS
MUMBAI INDIANS
IPL UPDATES
VIVO IPL 2018
VIVO IPL 11
VIVO IPL LIVE SCORES
DREAM 11
CRICBUZZ

What are jQuery Events? Syntax For Event Methods

- No comments

What are Events?
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.
  • moving a mouse over an element
  • selecting a radio button
  • clicking on an element
The term "fires/fired" is often used with events. Example: "The keypress event is fired, the moment you press a key".
Here are some common DOM events:
Mouse Events
Keyboard Events
Form Events
Document/Window Events
click
keypress
submit
load
dblclick
keydown
change
resize
mouseenter
Keyup
focus
scroll
mouseleave

blur
Unload

jQuery Syntax For Event Methods

In jQuery, most DOM events have an equivalent jQuery method. To assign a click event to all paragraphs on a page, you can do this:
$("p").click();
The next step is to define what should happen when the event fires. You must pass a function to the event:
$("p").click(function(){
  // action goes here!!
});

Commonly Used jQuery Event Methods

$(document).ready()
The $(document).ready() method allows us to execute a function when the document is fully loaded.
click()
The click() method attaches an event handler function to an HTML element. The function is executed when the user clicks on the HTML element. The following example says: When a click event fires on a <p> element; hide the current <p> element:
$("p").click(function(){
   $(this).hide();
});
dblclick()
The dblclick() method attaches an event handler function to an HTML element. The function is executed when the user double-clicks on the HTML element:
$("p").dblclick(function(){
   $(this).hide();
});
mouseenter()
The mouseenter() method attaches an event handler function to an HTML element. The function is executed when the mouse pointer enters the HTML element:
$("#p1").mouseenter(function(){
    alert("You entered p1!");
});
mouseleave()
The mouseleave() method attaches an event handler function to an HTML element. The function is executed when the mouse pointer leaves the HTML element:
$("#p1").mouseleave(function(){
    alert("Bye! You now leave p1!");
});
mousedown()
The mousedown() method attaches an event handler function to an HTML element. The function is executed, when the left, middle or right mouse button is pressed down, while the mouse is over the HTML element:
$("#p1").mousedown(function(){
    alert("Mouse down over p1!");
});
mouseup()
The mouseup() method attaches an event handler function to an HTML element. The function is executed, when the left, middle or right mouse button is released, while the mouse is over the HTML element:
$("#p1").mouseup(function(){
    alert("Mouse up over p1!");
});
hover()
The hover() method takes two functions and is a combination of the mouseenter() and mouseleave() methods. The first function is executed when the mouse enters the HTML element, and the second function is executed when the mouse leaves the HTML element:
$("#p1").hover(function(){
    alert("You entered p1!");
},
function(){
    alert("Bye! You now leave p1!");
});
focus()
The focus() method attaches an event handler function to an HTML form field. The function is executed when the form field gets focus:
$("input").focus(function(){
    $(this).css("background-color", "#cccccc");
});
blur()
The blur() method attaches an event handler function to an HTML form field. The function is executed when the form field loses focus:
$("input").blur(function(){
    $(this).css("background-color", "#ffffff");
});

The on() Method

The on() method attaches one or more event handlers for the selected elements. Attach a click event to a <p> element:
$("p").on("click", function(){
    $(this).hide();
});
Attach multiple event handlers to a <p> element:
$("p").on({
    mouseenter: function(){
        $(this).css("background-color", "lightgray");
    }, 
    mouseleave: function(){
        $(this).css("background-color", "lightblue");
    }, 
    click: function(){
        $(this).css("background-color", "yellow");
    } 
});

Why jQuery? How do I use jQuery?

- No comments

Why jQuery?
There are lots of other JavaScript frameworks out there, but jQuery seems to be the most popular, and also the most extendable. Many of the biggest companies on the Web use jQuery, such as:
  • Google
  • Microsoft
  • IBM
  • Netflix

How do I use jQuery?

First off, you should learn some basics. jQuery, like many other libraries, uses the global $ variable as a shortcut. Basically, window.jQuery === window.$ (and therefore, $("div") and jQuery("div") are identical. You can use whichever you prefer, but $ is shorter and neater, it also provides better readability since it’s easier to spot than jQuery, which is a more conventional name for a variable (being plain text). There are two parts to jQuery. There are methods which run on collections and rely on $.fn (a shortcut for $.prototype). There are then utility methods which run directly on $—for example $.data() and $.ajax(), which don’t require a collection to work.

jQuery Syntax

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
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)
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".
$(document).ready(function(){
   // jQuery methods go here...
});
This is to prevent any jQuery code from running before the document is finished loading (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
$(function(){
   // jQuery methods go here...
});
Use the syntax you prefer. We think that the document ready event is easier to understand when reading the code.

jQuery Selectors

jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors. All selectors in jQuery start with the dollar sign and parentheses: $().

The element Selector

The jQuery element selector selects elements based on the element name. You can select all <p> elements on a page like this:
$("p")
When a user clicks on a button, all <p> elements will be hidden:
$(document).ready(function(){
   $("button").click(function(){
   $("p").hide();
   });
});

The #id Selector

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")
When a user clicks on a button, the element with id="test" will be hidden:
$(document).ready(function(){
   $("button").click(function(){
   $("#test").hide();
   });
});

The .class Selector

The jQuery class selector finds elements with a specific class. To find elements with a specific class, write a period character, followed by the name of the class:
$(".test")
When a user clicks on a button, the elements with class="test" will be hidden:
$(document).ready(function(){
   $("button").click(function(){
   $(".test").hide();
  });
});
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


How do I use jQuery? Part 2

- No comments


The most common methods

So, now that you are somewhat familiar with jQuery’s power and syntax, you should feel more comfortable working with it. Let me introduce you to a few things that can help you along your way.
Two of the most used methods that jQuery has to offer. They find elements inside other elements, and filter the collection, respectively.
<div id="foo" class="parent">
    <div class="bar"></div>
    <div class="bar"></div>
</div>

<div id="baz" class="parent">
    <p class="bar"></p>
</div>
Let’s say I wanted to find all .bar elements within all .parent elements…
// this will give you a collection with all three .bar elements
$(".parent").find(".bar");

// this will give you a collection with one .bar element
$("#baz").find(".bar");
Really useful, isn’t it? To accompany .find() we have .filter(), which doesn’t dig into the elements you already have and look for others, it filters the elements you already have in your collection.
// get all three .bar elements again, but filter out everything
// that isn't a `p` element, so we end up with just one element
$(".parent").find(".bar").filter("p");
.on() and .off()
Previously .bind().delegate() and .live(), is used to bind events. The syntax is really easy:
$("#foo").on("click", function(evt) {
    // do something when user clicks on the #foo element
});
There’s also built-in support for event delegation, which is basically that you bind an event on an element you know won’t change, instead of on elements that might. Let’s go back to our markup again, the #foo element has two .bar elements in it. Instead of binding two events and break future .barelements to work without having to bind a third, fourth, and fifth event; we use delegation. The only thing different from the normal syntax in the code example above, is that we add a parameter in the middle between the event type and the event handler, and we originate the event from the parent, #foo, instead of binding it directly to the .bar elements.
$("#foo").on("click", ".bar", function(evt) {
    // do something when user clicks on .bar elements,
    // existing and future ones alike
});
.ajax() and its helpers
While straight-up interaction with your webpage is nice, you often have a need to pull in data asynchronously so that your user doesn’t constantly have to refresh your page. This is done using $.ajax(), or some of its helpers:
·         $.get() - Gets data from an URL
·         $.getJSON() - Same as above, but automatically returns a JavaScript object with your data (instead of a string)
·         $.post() - Submits data to an URL
·         $.fn.load() - Loads data from an URL into your jQuery collection
There are a few others, more obscure, that I’ll let you look up if you want to know. First off, before we go into detail on the different helpers; they all use $.ajax behind the scenes, with predefined values. Everything you can do with the helpers, is possible (and are done) with $.ajax().
To simply retrieve data from your server, you need a few properties to send into $.ajax():
$.ajax({
    url: "/some/path/mydata.html",
    success: function(data) {
        // do something with `data` that you retrieved
        // from the server
    }
});
Introduced in jQuery 1.5, you can also do:
$.ajax({
    url: "/some/path/mydata.html"
}).done(function(data) {
    // do something with `data` that you retrieved
    // from the server
});
How this works is a bit out of scope for this article, but for now, just imagine that it works exactly as the first example. I personally prefer the second example, because it doesn’t clutter the AJAX, you can easily see what you’re requesting, and how you do it, and what you do when the data has been retrieved.
That said, let’s us look at how the helpers work. Remember, they all use $.ajax() in the background.
$.get()
When you simply want to retrieve data, $.get() is your friend. The simplest usage looks like this:
$.get("/some/path/mydata.html", function(data) {
    // do something with `data` that you retrieved
    // from the server
});
It does support more parameters, but I think you can see that for yourself should you ever need to use it on a more advanced level.
$.post()
This one is super useful if you ever need to submit a form, for example. It does a lot of work for you so you don’t have to repeat yourself every time you want to push data back to the server. Let’s say you have this form on your webpage:
<form method="post" action="/some/path/form.php" id="userform">
    <label for="username">Username:</label>
    <input id="username" name="username" />
    <label for="password">Password:</label>
    <input id="password" name="password" type="password" />
    <input type="submit" />
</form>
When the form is submitted, we want to use AJAX to send that data over to the server, instead of actually reloading the page and send the user to form.php. First off, we’re going to bind the submitevent on the form, and cancel that so the browser doesn’t send the user to the action URL. Then we’re going to serialize the form using $.fn.serialize() into a data format that is recognizable by the server, and lastly, we send that data over.
// cache our form
var userform = $("#userform");

// bind the `submit` event
userform.on("submit", function(evt) {
    // serialize the form
    var data = userform.serialize();

    // POST the data to the server using the form's action URL
    $.post(userform.attr("action"), data, function() {
        // Data sent, let's clear the form elements
        userform.find("input, select, textarea").val("");
    });

    // Make sure the browser doesn't send the user over
    // to the action URL
    evt.preventDefault();
});
It’s quite a bit more advanced than the other examples, but when you understand this, you’ll have a much better image of how you can use jQuery to do awesome things rather simple (especially compared to vanilla/normal JavaScript).
I think that’s all for now, I hope you found this post somewhat useful and please let me know if you have any questions, I’m @peolanha on twitter and peol on FreeNode (IRC). I’d also like to thankAddy Osmani who reviewed this article both linguistically and technically.