Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Different ways to refresh or reload page using jQuery

Nov 28, 2011 Posted by Lara Kannan 0 comments
In this post, I will show you the different ways using which you can reload or refresh the webpage using jQuery. The first method is nothing to do with jQuery. It is a HTML tag which you need to put in the head section of your page and your page will get refreshed automatically after specified interval.

<meta http-equiv="refresh" content="10">

The meta tag with "http-equiv" is used to refresh the page. This attribute tells the browser that this meta tag is sending an HTTP command rather than a standard meta tag.

Refresh is an actual HTTP header used by the web server.The content attribute in the tag is having value in seconds. As per the above code, it is set to 10, which means after 10 seconds your page will get refreshed or reloaded.

You can also use jQuery to refresh/reload the page automatically. See below jQuery code.
function ReloadPage() { 
   location.reload();
};
 
$(document).ready(function() {
  setTimeout("ReloadPage()", 10000); .
});
location.reload() will reload the page again. The advantage of location.reload() is that it works with all the major browsers.

If you want to reload the page on click of button, then you can call location.reload() on button click event. See below jQuery code.
$(document).ready(function() {
     $('#btnReload').click(function() {
             location.reload();
       });
}); 

Hope this post will help you!

Share

Creating Your Own jQuery Custom Selector

Posted by Lara Kannan 1 comments
jQuery supports a large subset of selectors defined by the CSS3 Selectors draft standard. Additionally it also contains some very useful pseudo classes (similar to :first-child, :hover etc).

Due to its extensible framework, the best part is that jQuery lets you create and define your own custom selectors with ease. A full list of jQuery selectors is available on the jQuery site.

In this article, we will learn how to create our own custom selector that identifies all the mailto: links on a page. Let us see some code first:


As you can observe, we have extended jQuery’s selector expressions under the jQuery.expr[':'] object. To learn more about this, visit the jQuery hot Selector engine called sizzle. We have defined a custom selector called :mailToLink to which we are passing an object, which is a collection of links. This selector looks for all anchor elements that contains an href attribute matching mailto.

That’s it. Our selector :mailToLink is ready and here’s how we can use it:

To test this selector, we have used some hyperlinks, out of which one of them is a mailto: link. When you click the button, we use our custom selector to indentify the :mailto link and set it’s color to red.

As you can see, we have extended jQuery’s expression engine with ease!

The entire source code of this article can be downloaded over here. I hope you liked the article and I thank you for viewing it.

Source: www.dotnetcurry.com


Hope this post will help you!

Share

Best way of using jQuery Selector

Posted by Lara Kannan 0 comments
It is pretty important to understand how to write efficient element selection statement. One has to be very careful while jQuery selector statement. Below are some tips on how to use your jQuery selectors efficiently.

1. Always try to use ID as selector

You can use ID as selector in jQuery. See below jQuery code.
$("#elmID");
When IDs are used as selector then jQuery internally makes a call to getElementById() method of Java script which directly maps to the element. When Classes are used as selector then jQuery has to do DOM traversal.So when DOM traversal is performed via jQuery takes more time to select elements. In terms of speed and performance, it is best practice to use IDs as selector.

2. Use class selector with tags

You can use CSS classes as selector. For example, to select elements with "myCSSClass" following jQuery code can be used.
$(".myCSSClass");
As said earlier, when classes are used DOM traversal happens. But there could be a situation where you need to use classes as selector. For better performance, you can use tag name with the class name. See below
$("div.myCSSClass");
Above jQuery code, restricts the search element specific to DIV elements only.

3. Keep your selector simple, don't make it complex

Avoid complex selectors. You should use make your selectors simple, unless required.
$("body .main p#myID em");
Instead of using such a complex selector, we can simplify it. See below.
$("p#myID em");

4.Don't use your selector repeatedly.

See below jQuery code. The selectors are used thrice for 3 different operation.
$("#myID").css("color", "red"); $("#myID").css("font", "Arial"); $("#myID").text("Error occurred!");
The problem with above code is, jQuery has to traverse 3 times as there are 3 different statements.But this can be combined into a single statement.
$("p").css({ "color": "red", "font": "Arial"}).text("Error occurred!");

5.Know how your selectors are executed

Do you know how the selectors are executed? Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".
$("p#elmID .myCssClass");

Hope this will help you. Happy coding!!!!

Share
Labels: ,

Free ebook - jQuery Recipes: A Problem-Solution Approach

Apr 26, 2010 Posted by Lara Kannan 0 comments
jQuery Recipes: A Problem-Solution Approach

jQuery is one of today’s most popular JavaScript web application development frameworks and libraries. jQuery Recipes can get you started with jQuery quickly and easily, and it will serve as a valuable long-term reference.

  • The book begins with small initial problems that developers typically face while working with jQuery, and gradually goes deeper to explore more complex problems.

  • The solutions include illustrations and clear, concise explanations of the code. Using this book and jQuery, your web sites will be more dynamic and lively.


Product Details

  • Paperback: 350 pages
  • Apress (January 11, 2010)
  • Language: English
  • ISBN-10: 1430227095
  • ISBN-13: 978-1430227090

Free Download Links :

1. Hotfile Link
http://hotfile.com/.../Apress.jQuery.Recipes.Jan.2010.rar.html

2. Rapidshare Link
http://rapidshare.com/.../Apress.jQuery.Recipes.Jan.2010.rar

3. Megauplopad Link
http://www.general-search.com/go/620092793

4. Socifiles Link
http://socifiles.com/d/b7fdac


If you like this post, please add your comments and 'A thanks' would be nice.

Thanks : www.google.com

Share
Labels:

Checkbox Validation using jQuery?

Jan 22, 2010 Posted by Lara Kannan 0 comments
How to validate the checkbox using Jquery?

In the HTML form have multiple chekcbox in same using html array element. That time we will use three types of checkbox validation for checked or not.

Multiple checkbox validation has three types.
  • Checkbox validation using Id
  • Checkbox validation using name
  • Checkbox validation using div tag
Let we see via examples:

Take the below html/aspx code likes ...

<form>
<div id="checkboxId">
<input type="checkbox" name="chkBox[]" id="chkBox[]">
<input type="checkbox" name="chkBox[]" id="chkBox[]">
<input type="checkbox" name="chkBox[]" id="chkBox[]">
</div>

<input type="button" name="Btnaction"
value="submit" onclick="return validateId();">
</form>
</div>

// Calling jquery file.
<script language="javascript" src="jquery.js" type="text/javascript"></script>

1. Checkbox validation using Id

<script language="javascript">
function validateId()
{
var selector_checked = $("input[@id=chkBox]:checked").length;
alert(selector_checked);
if (selector_checked == 0)
{
return false;
}
else if (selector_checked == 0)
{
return false;
}
else
{
return true;
}
}
</script>

2. Checkbox validation using Name

Replace the function name from 'validateId' to 'validateName' in the above html/aspx code.

function validateName()
{
var selector_checked = $("input[@name=chkBox]:checked").length;
alert(selector_checked);
if (selector_checked == 0)
{
return false;
}
else if (selector_checked == 0)
{
return false;
}
else
{
return true;
}
}

3. Checkbox validation using Div tag

Replace the function name from 'validateName' to 'validateDiv' in the above html/aspx code.

function validateDiv()
{
if($("#checkboxId input[type='checkbox']:checked").length > 0)
{
return true;
}
}

4. Single checkbox validation.

<div>
<input type="checkbox" name="chkBox[]" id="chkTCAgree" />Agree terms and condition
text here<br />
<input type="button" name="Btnaction" value="submit" onclick="return validateTC();" />
</div>

function validateTC() {
var agree = $('#chkTCAgree').attr('checked');
if (!agree) {
alert("please accept the terms and conditions");
return false;
}
}

Enjoy the technology!

Share
Labels: ,

How to add jQuery intellisense in Visual Studio 2008

Dec 31, 2009 Posted by Lara Kannan 0 comments
How to add jQuery intellisense in Visual Studio 2008. I will discuss the below items :

  • How to add jQuery intellisense in .aspx page.

  • How to add jQuery intellisense in external javascript file.


Step 1 : Install Visual Studio 2008 Service Pack 1

To see whether you have already installed version of Visual Studio 2008 Service Pack 1.
1. Open Visual Studio 2008. Go to Help--->About Microsoft Visual Studio.

2. About Microsoft Visual Studio window will open.
You may here Version 9.0.30729.1 SP or later version.
If Visual Studio service pack is not installed then your first step is to install it.

Step 2 : Download and install VS2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files

You can get information regarding hot fix in detail on below links
http://blogs.msdn.com/...doc-files-is-now-available.aspx

http://code.msdn.microsoft.com/.../ProjectReleases.aspx?ReleaseId=1736

Step3 : Download the jQuery-vsdoc.js file

Go to http://docs.jquery.com/...#Download_jQuery

You will find different releases of jQuery. The latest release is jQuery 1.3.2.

Click Visual Studio link in front of Documentation tag. You will be redirected to next page. In next page you can found the link for downloading jQuery-vsdoc.js file

Step 4: Rename the downloaded file

After downloading that rename it as follows.

1. Rename jquery-1.3.2-vsdoc2.js into jquery-1.3.2.min-vsdoc.js

2. Rename jquery-1.3.2.js into jquery-1.3.2.min.js



How to add jQuery intellisense in .aspx page.

In the .aspx page, add the reference jquery-1.3.2.min.js file into .aspx page. Here I have my script file under scirpts folder.

 <script src="scirpts/jquery-1.3.2.min.js" type="text/javascript"> </script> 

Now press CTRL+ SHIFT+J to update the Jscript intellisense or Go to Edit ---> IntelliSense ---> Update Jscript Intellisense. You will see Update JScript Intellisense message in the status bar.

That's all. Now you can test that your jQuery intellisense has started working.



How to add jQuery Intellisense in External javascript file

1. Add the reference of jQuery file at the top of My.js file
/// <reference path = "jquery-1.3.2.min.js" /> 

2. Now press CTRL+ SHIFT+J to update the Jscript intellisense or Go to
Edit ---> IntelliSense ---> Update Jscript Intellisense.

That's all. Make your light weight web application by using jQuery.

Hope this will be helpfull.

Share
Labels: ,

Free eBook - jQuery Cookbook Dec 2009

Dec 29, 2009 Posted by Lara Kannan 1 comments
Free download jQuery Cook book Dec 2009 edition.

Use of jQuery :
  • Create better, cross-platform JavaScript code

  • Learn detailed solutions to specific client-side problems

  • For web designers who want to create interactive elements for their designs

  • For developers who want to create the best user interface for their web applications and so on...


Downloads :
Megaupload

Rapidshare

Hotfile

Mediafire

Password :
www.updatebooks.com

A 'Thank You' would be nice! I hope this will be useful.
Thanks : Katz

Share
Labels: ,