Add a class to html in jquery

here i am going to show you how we can add a class of css to html elements like a,p,h3 etc. You can see demo by copy Below given code and paste in text editor and save as html file and open in a web browser. you can download latest version of jquery from here [download jquery]-
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Attach Class Jquery</title>
<style>
.links{
color:#F39;
font-family:”Trebuchet MS”, Arial, Helvetica, sans-serif;
font-size:14px;
}
.paragraphs{
color:#36F;
font-family:Georgia, “Times New Roman”, Times, serif;
font-size:12px;
}
.headings{
color:#0F0;
font-family:”Times New Roman”, Times, serif;
font-size:18px;
}
.hlists{
display:inline;
}
</style>
<script src=”jquery-1.4.2.js” language=”javascript” type=”text/javascript”></script>
<script>

$(function(){
$(“a”).addClass(‘links’);
$(“p”).addClass(‘paragraphs’);
$(“h3”).addClass(‘headings’);
$(“#nav ul li”).addClass(‘hlists’);
});
</script>
</head>
<body>
<!– wrap starts here –>
<div id=”wrap”>
<!–header –>
<div id=”header”>
<h1><a href=”http://www.amandip.com/” title=””>Aman Dhaliwal</a></h1>
<p>Everyday Is A Gift That’s Why It Is Called The Present</p>
<div>
<p>
<a href=”http://www.amandip.com/”>Home</a> |
<a href=”http://www.amandip.com/contact”>Contact</a> |
<a href=”http://www.amandip.com/sitemap”>Site Map</a>
</p>
</div>
<!–header ends–>
</div>
<!– navigation starts–>
<div id=”nav”>
<ul>
<li id=”current”><a href=”http://www.amandip.com/”>Home</a></li>
<li><a href=”http://www.amandip.com/projects”>Projects</a></li>
<li><a href=”http://www.amandip.com/codesamples”>Code Samples</a></li>
<li><a href=”http://www.amandip.com/about”>About Me</a></li>
<li><a href=”http://www.amandip.com/contact”>Contact Me</a></li>
</ul>
<!– navigation ends–>
</div>
<!– content-wrap starts –>
<div id=”content-wrap”>
<div id=”main”>
<h2><a href=”http://www.amandip.com/”>Welcome</a></h2>
<p>Welcome to my personal website…</p>
<p>Within you will find my recent and past web design projects, as well as my online resume and contact information.</p>
<p>Personal Info</p>
<p>Growing up online, I became fascinated with almost everything digital. I consider myself a self-taught web designer and an avid web coder. Designing websites has been a long passion of mine. To get in touch with me, please use contact form. You can also view my e-mail address and contact information.</p>

<!– main ends –>
</div>
<div id=”sidebar”>
<h3>Menu</h3>
<ul>
<li><a href=”index.html”>Home</a></li>
<li><a href=”#”>Java</a></li>
<li><a href=”#”>C</a></li>
<li><a href=”#”>C++</a></li>
<li><a href=”#”>PHP/MySQL</a></li>
</ul>
<h3>Wise Words</h3>
<p>”Trials teach us what we are; they dig up the soil,
and let us see what we are made of.” </p>
<p>- Charles Haddon Spurgeon</p>
<!– sidebar ends –>
</div><!– content-wrap ends–>
</div><!– footer starts –>
<div id=”footer-wrap”>
<div id=”footer-columns”>
<div>
<h3>My Websites</h3>
<ul>
<li><a href=”http://amandip.brinkster.net/”>http://amandip.brinkster.net/</a></li>
<li><a href=”http://amandip.web.officelive.com”>http://amandip.web.officelive.com</a></li>
<li><a href=”http://aman.coolpage.biz/”>http://aman.coolpage.biz/</a></li>
<li><a href=”http://amandhaliwalzblog.blogspot.com/”>http://amandhaliwalzblog.blogspot.com/</a></li>
<li><a href=”http://sites.google.com/site/amandipclub”>http://sites.google.com/site/amandipclub</a></li>
</ul>
</div>
<div>
<h3>My Projects</h3>
<ul>
<li><a href=”http://www.vancouver-seo.net/”>Vancouver SEO</a></li>
<li><a href=”http://www.indiaseocompany.net/”>India SEO</a></li>
<li><a href=”http://www.princessweddingphotography.ca”>Princess Wedding Photography</a></li>
<li><a href=”http://www.thetechnocare.com/”>Technocare Nursery</a></li>
<li><a href=”http://www.cyberstarinfotech.com/index1.php”>Cyberstar Infotech</a></li>
</ul>
</div>
<!– footer-columns ends –>
</div>
<!– footer ends–>
</div>
<!– wrap ends here –>
</div>
</body></html>

Google Maps with JQuery

Here i am going to write a small code of javascript and jquery to show a google map on webpage. Before trying this you should have Google Maps API Key and latitude and longitude of place you want to show at the center of map. By the way here i have given a sample latitude & longitude values, which gives the location of Ludhiana City, Punjab in India. You can download your Google Maps API Key here. Get a Google Maps API Key



Demo –

 

enable disable in jquery

Hello Everybody, here i am going to show, how you can enable or disable a combobox with jquery. you can download latest version of jquery from here [download jquery]. In this code i used two functions of jquery for adding and removing a attribute(disabled).
Jquery function attr(‘name’,’value’) is used to add an attribute to an html element. Function removeAttr(‘name’) is used to remove a attribute of html element by using jquery.
Insert a combobox using following code :
<select id=”mycombo” style=”width:200px;”>
<option>one</option>
<option>two</option>
</select>

Insert two buttons containg jquery code in click event, using following code :
<input type=”button” value=”Disable” onclick=”$(‘#mycombo’).attr(‘disabled’,’disabled’)”/>
<input type=”button” value=”Enable” onclick=”$(‘#mycombo’).removeAttr(‘disabled’)”/>

Check Uncheck checkbox in jquery

Hello Everybody, here i am going to show, how you can check or uncheck a checkbox with jquery. you can download latest version of jquery from here [download jquery]. In this code i used two functions of jquery for adding and removing a attribute(disabled).
Jquery function attr(‘name’,’value’) is used to add an attribute to an html element. Function removeAttr(‘name’) is used to remove a attribute of html element by using jquery.
Insert a checkbox using following code :
<input type=”checkbox” id=”mycbox”/>Click on buttons to check/uncheck.

Insert buttons using the following code :
<input type=”button” value=”Check” onclick=’$(“#mycbox”).attr(“checked”,”checked”)’/>
<input type=”button” value=”Uncheck” onclick=’$(“#mycbox”).removeAttr(“checked”)’/>

getting value and text-value of select in jquery

Hello Everybody, here i am going to show, how you can get value and textvalue of a select element with jquery. you can download latest version of jquery from here [download jquery]. In this code i used two functions of jquery for getting value(val()) and text(text()) of selected option of a select or combobox.
Insert following code in webpage :
<select id=”myselect”>
<option value=”1″>Javascript</option>
<option value=”2″>Jquery</option>
<option value=”3″>PHP/Mysql</option>
<option value=”4″>Asp.net</option>
<option value=”5″>Java</option>
</select>
<input type=”button” value=”Get Value” onclick=”alert($(‘#myselect’).val())”/>
<input type=”button” value=”Get Text Value” onclick=”alert($(‘#myselect option:selected’).text())”/>

Viagra is the most famous ‘love pill’ in the world, but it is not the only option for you. The majority of men who tried both brand and generic pills state that Cialis (the most famous and top-quality generic drug) works better. It is up to you to decide whether you choose brand pills or buy Cialis, but ED patients state that:
Now it is possible to avoid awkward publicity if you buy Cialis online in our reliable web pharmacy. To purchase Cialis online simply place your order, use your credit card to pay for your pills, cialis 10mg receive your drug per post in a decent package and start your way to perfect men’s health!

Before starting our conversation about Viagra, let us mention some facts about ED. You will be surprised to find out that healthy sex life is more than great pleasure and ability to have children. It is the best and only way to guarantee natural training of the male heart, lungs, blood vessels and muscles. It is also the most efficient way of restoring male central nervous system. Normal sex life prevents the development of such severe diseases as stroke, heart attack, viagra no prescription non generic high blood pressure (hypertension), diabetes, cancer, neurosis, depression, dementia etc. Now you know that men think the worlds of their erectile function for a reason!

You can buy Viagra in the nearest drugstore if you have a prescription from your doctor. It means, your awkward health disorder becomes public inevitably. Do not be frustrated! Fortunately, you can avoid any publicity at all if you choose to buy Viagra online. Our reliable online pharmacy will offer you top-quality pills from the manufacturer at the best price.

Attention! viagra no prescription non generic Do not fail to see your doctor before ordering Viagra online! Use the lowest dose of the drug that works. Never overdose your ‘love pills’ – take only 1 pill about 1 hour before intended intercourse. Never take Viagra repeatedly within 24 hours!

reset a form in jquery

you can download latest version of jquery from here [download jquery]. You can use below demo code to reset a html form. Copy and insert the following code to create a form and jquery code.
<script>
$(document).ready(function() {
$(“#reset”).click(function() {
$(“#myform”).reset();
});
});
</script>
<form id=”myform” method=”post” action=”#”>
<input type=”text” name=”n1″ size=”15″ />
<input type=”text” name=”n2″ size=”15″ />
<input type=”text” name=”n3″ size=”15″ />
<input type=”reset” name=”reset” id=”reset” value=”reset” />
</form>

hide animate paragraph in jquery

you can download latest version of jquery from here [download jquery]. You can use below demo code to insert and hide a paragraph in slow speed. Copy and insert the following code :

<script>
$(function(){
$(“div.contents p[class^=para]“).click(function(){
$(this).hide(“slow”);
});
});
</script>
<div class=”contents”>
<p class=”para1?>Punjab is a state in northwest India. The Indian state borders the Pakistani province of Punjab to the west, Jammu and Kashmir to the north, Himachal Pradesh to the northeast, Chandigarh to the east, Haryana to the south and southeast and Rajasthan to the southwest. The total area of the state is 50,362 square kilometres (19,445 square miles). Punjab’s capital is Chandigarh, which is administered separately as a Union Territory since it is also the capital of neighbouring Haryana. Other major cities of Punjab include Mohali, Ludhiana, Amritsar, Bathinda, Patiala and Jalandhar.</p>
<p class=”para2?>The Indian Punjab historically forms a part of the larger Punjab region, which includes the Pakistani provinces of Punjab and North-West Frontier Province; the Indian states of Haryana, Himachal Pradesh, parts of Jammu and Kashmir and the Union Territory of Chandigarh. After the partition of India in 1947, the Punjab province of British India was divided between India and Pakistan; the Indian Punjab was further trifurcated in the year 1966 leading to the formation of Haryana and Himachal Pradesh.</p>
<p class=”para3?>Agriculture is the largest industry in Punjab, it is the largest single provider of wheat to India. Others major industries include the manufacture of scientific instruments, electrical goods, financial services, machine tools, textiles, sewing machines, sports goods, starch, tourism, fertilizers, bicycles, garments, and the processing of pine oil and sugar.</p>
</div>

Create WordPress Theme

Today i am going to show you which files are needed or created to create a wordpress theme. This is a small tutorial which covers only the basics of theme creation, so it give you a clear view how to start creating themes of wordpress. You can download wordpress from wordpress.org.

Commonly Used WordPress Theme Files

404.php -Error page, served up when someone goes to a URL on your site that doesn’t exist
archive.php – Page that displays posts in one particular day, month, year, category, tag, or author
comments.php – This file delivers all the comments, pingbacks, trackbacks, and the comment form when called
footer.php – Included at the bottom of every page. Closes off all sections. (Copyright, analytics, etc)
header.php – Included at the top of every page. (DOCTYPE, head section, navigation, etc)
images – a Folder – Keeps all the images that make up your theme in one place
index.php – This is typically the “homepage” of your blog, but also the default should any other views be missing
page.php – Template for Pages, the WordPress version of static-style/non-blog content
screenshot.png – This is the image thumbnail of your theme, for help distinguishing it in the Appearance picker
search.php – The search results page template
sidebar.php – Included on pages where/when/if you want a sidebar
single.php – This file is displays a single Post in full (the Posts permalink), typically with comments
style.css – The styling information for your theme, required for your theme to work, even if you don’t use it

Create a file named screenshot.png and put it in your themes folder (300px x 225px in size)
Put this info at the top of your style.css file
/*Theme Name: Theme NameTheme URI: http://your-website.com/cool-theme/Description: Totally awesome WordPress theme by <a href="http://your-website.com/">Yours Truly</a>Version: 1 (WP2.8.4)Author: Your NameAuthor URI: http://your-website.com/Tags: super, awesome, cool, sweet, potato nuggets*/
header.php
The header file is the first file that is called when WordPress is rendering any type of web page. As such, its contents begin with the DOCTYPE.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
After DOCTYPE element is the opening HTML tag.
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
After the opening <html> tag, we move into the <head>.. Within the <head> section, we begin with <meta> tags.
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
Other important meta tags include “description” (very important) and “keywords” (less important). But because the description and keywords for any given page on your site depend on the actual content of that page, it is best to dynamically generate these tags rather than include them directly here.
Simply use this code as the <title> element in your theme’s header.php file and you’re good to go:

<title>
<?php if (function_exists('is_tag') && is_tag()) {
single_tag_title('Tag Archive for "'); echo '" - ';
} elseif (is_archive()) {
wp_title(''); echo ' Archive - ';
} elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - ';
} elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - ';
} elseif (is_404()) {
echo 'Not Found - ';
}
if (is_home()) {
bloginfo('name'); echo ' - '; bloginfo('description');
} else {
bloginfo('name');
}
if ($paged > 1) {
echo ' - page '. $paged;
} ?>
</title>

The <head> is also the place to link to external resources like CSS and JavaScript files. Since your theme requires the presence of a style.css file in the root directory of your theme, you might as well use it.
<link rel='stylesheet' href='<?php bloginfo("stylesheet_url"); ?>' type='text/css' media='screen' />
The parameterized function, bloginfo(“stylesheet_url”), returns the exact URL of the stylesheet.
you want to include the popular JavaScript library jQuery on your page. WordPress ships with a copy of jQuery you can link to. To do so, simply call this function in your head area or functions.php file:
<?php wp_enqueue_script('jquery'); ?>
You can load your own script on the page like this:
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/myscript.js"></script>
bloginfo function here outputs the URL path to the active theme directory. You can also link your custom css like below
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/listings.css" type="text/css" media="screen" />

The wp_head() Function

A must for any theme, the wp_head() function simply tells WordPress “Right here, this is inside the <head>.” It is kind of a generic function that is used as a “hook” on which the WordPress core, plugins, and custom functions may attach things. In the previous section, the code uses the wp_enqueue_script function. All by itself, that function doesn’t have any effect. But when the wp_head tag is also present, it serves as a hook that serves as the location at which the wp_enqueue_script function will load the script.
Plugins also use the wp_head function to load their own scripts and CSS files.

Blog_info() function:

there is a WordPress function for pulling out a variety of information about your blog. This information is useful on a regular basis when creating themes. Here is the function…
<?php bloginfo('template_url'); ?>
…and here is the different types of data that you can get from it:
admin_email = mail@amandip.com
charset = UTF-8
comments_rss2_url = http://www.amandip.com/comments/feed/
description = Improve Your WordPress Skills to the Top Level!
url = http://www.amandip.com/
html_type = text/html
language = en-US
name = Help of WordPress
rdf_url = http://amandip.com/home/feed/rdf
rss2_url = http://amandip.com/home/feed
rss_url = http://amandip.com/home/feed/rss
siteurl = http://amandip.com/
stylesheet_directory = http://amandip.com/wp-content/themes/mytheme
stylesheet_url = http://amandip.com/wp-content/themes/mytheme style.css
template_directory = http://amandip.com/wp-content/themes/mytheme
template_url = http://amandip.com/wp-content/themes/mytheme
text_direction = ltr
version = 2.8.5
wpurl = http://amandip.com/
Loop used to display posts after checking posts are available or not :

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php echo get_post_meta($post->ID, 'PostThumb', true); ?>
<p>
<span>Posted on</span> <?php the_time('F jS, Y'); ?> <span>by</span> <?php the_author(); ?>
</p>
<?php the_content('Read Full Article'); ?>
<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', '); ?> <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p>
</div>
<?php endwhile; ?>
<?php next_posts_link('Older Entries'); ?>
<?php previous_posts_link('Newer Entries'); ?>
<?php else : ?>
<h2>Nothing Found</h2>
<?php endif; ?>

Here is a number of common and highly useful “inside-loop-only” functions:
• the_permalink() – displays the permalink URL for each post
• the_ID() – displays the ID of each post
• the_author() – displays the name of the author for each post
• the_category() – displays the category/categories to which each post belongs

While you are inside the loop, you also have access to a bunch of preset variables that are populated after the_post() is executed. These variables exist in the object $post.
$post->ID – returns the ID of post; useful for other functions that need an ID.
• $post->post_content – the actual post content, including all markup; useful when you need to process the content of a post before outputting it.
• $post->post_modified – returns the datestamp of the last time the post was updated.
• $post->post_name – returns the slug of the post.
Some Common “Outside Loop” Functions
Here is a number of common and frequently used “outside-loop-only” functions:
• wp_list_pages() – displays a list of links to your static pages
• next_posts_link() – displays a link to older posts in archive views
• wp_tag_cloud() – displays a tag cloud of all your tags
• get_permalink() – returns the permalink of a post for use in PHP
To check which query is used by wordpress to handle a page, simply put following variable in the file:
<?php echo $query_string; ?>

Show sidebar on some pages and hide in others
you want some of your Pages to display your regular sidebar, and hide it from some of your other Pages. Apart from this difference, all of your pages will be exactly the same. A better approach is to use a custom field to designate if you want to have a sidebar or not. Then in the template, look for that custom field and behave accordingly. Here is how this could look in your index.php file:

<?php // conditional sidebar display
if (!get_post_meta($post->ID, "noSidebar", true)) {
get_sidebar();
} ?>

You could use this exact same technique for anything that you wish conditionally to include or not include on a page template, without having to create multiple templates.

Sidebars:

In any of your theme files where you wish to display a sidebar, simply place the following template tag where you would like it to appear:
<?php get_sidebar(); ?>
That function will go get the file “sidebar.php” and place its content where this function was called. Working with multiple sidebars?
<?php get_sidebar('secondary'); ?>
That function will retrieve the file called “sidebar-secondary.php” and load that.

List recent posts


<?php wp_get_archives(array(
'type' => 'postbypost', // or daily, weekly, monthly, yearly
'limit' => 10, // maximum number shown
'format' => 'html', // or select (dropdown), link, or custom
'show_post_count' => false, // show number of posts per link
'echo' => 1 // display results or return array
)); ?>

This will output a list of linked Post titles according to the specified parameters.

Display a tag cloud


<?php wp_tag_cloud(array(
'smallest' => 10, // size of least used tag
'largest' => 20, // size of most used tag
'unit' => 'px', // unit for sizing
'orderby' => 'name', // alphabetical
'order' => 'ASC', // starting at A
'exclude' => 9 // ID of tag to exclude from list
)); ?>

List of categories

<?php wp_list_categories(array(
'orderby' => 'name', // alphabetical
'order' => 'ASC', // starting at A
'show_count' => 0, // do NOT show # of posts per cat
'title_li' => __('Categories'), // include title list item
'exclude' => 12, // ID of category to exclude
'depth' => 0 // levels deep to go down cat tree
)); ?>

Widgetizing a sidebar, or any other region for which you wish to have manageable areas, is pretty easy.

<div id="sidebar">
<ul>
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) : ?>
<li><!-- stuff shown here in case no widgets active --></li>
<?php endif; ?>
</ul>
</div>
Now in your functions.php file, you “register” the sidebar with a custom function:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li id="%1$s">',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}

Now every widget you add will appear inside list tags with corresponding <h2> headings, which should fit well into the surrounding markup.

The Footer

Footers are so commonly used that WordPress again has a special template tag for including them into your theme:
<?php get_footer(); ?>
This function will accept only one parameter, a string, which works like the sidebar function. Used without a parameter it will fetch the footer.php file and insert it. When used with a parameter like so…
<?php get_footer("mini"); ?>
<?php get_footer("mega"); ?>
…the get_footer() template tag will retrieve the theme files “footer-mini.php” and “footer-mega.php,” respectively

The wp_footer() Hook

The wp_footer() hook is only used down in the footer instead. It tells WordPress, “the footer is right here.” All by itself, it doesn’t do anything, it’s just a generic hook that can be used to which scripts and other functionality may be attached.
For example, it is fairly common practice to load HTML-dependent JavaScript files from within the footer instead of the header. The location of the wp_footer() hook within your footer.php file will determine where the JavaScript is displayed in the source code. Thus, a good place for this hook is just before the closing <body> tag.
<?php wp_footer(); ?></body>
Just a thin black bar with a copyright and a small illustration in footer. Even that small bit of text could be kept dynamic:
© <?php echo date("Y"); bloginfo('name'); ?>

Functions.php

WordPress themes can include a special file, functions.php, which gives you a lot of control and power over things that happen in your theme. Think of it like a file that can do anything a plugin can do, without needing a plugin.Because the functions contained within the functions.php file reside within the theme folder itself, the code inside it depends on that particular theme being active in order to run. Plugins on the other hand, remain operational (or inoperational, as the case may be) regardless of which theme is active. Thus, don’t put anything in functions.php that is required by multiple themes. Likewise, don’t do anything with a plugin that is only relevant to the current theme.

Next Previous Buttons for MySql in PHP

Hello, today i am writing simple code how to iterate between lists of records in table. First of all php logic to maintain starting id of list and then a select query and after that adding buttons. The wrapper table will contain the records fetched from query results.

include("connection.php");
if(isset($_POST['startid']) && isset($_POST['nextbtn']))
{
$startid=$_POST['startid']+30;
}
else if(isset($_POST['startid']) && isset($_POST['prevbtn']))
{
if($_POST['startid']>=30)
{
$startid=$_POST['startid']-30;
}
else
{
$startid=0;
}
}
else
{
$startid=0;
}
$results=mysql_query("select * from customer_details order by id asc limit ".$startid.", 30 ");
if(mysql_num_rows($results)>0)
{
?>
<table id="customerslist" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
<tr><td colspan="12" align="center">
<form name="nextprev" id="nextprev" method="post" action="customerslist.php">
<table><tr>
<td style="border:none"><input type="submit" name="prevbtn" id="prevbtn" value="<< Previous List" /></td>
<td style="border:none"><input type="text" name="startid" id="startid" size="10" value="<?php echo $startid; ?>" style="display:none" /> </td>
<td style="border:none"><input type="submit" name="nextbtn" id="nextbtn" value="Next List >>" /></td></tr></table>
</form>
</td>

after the last td, all rows will contain fetched data and include 12 columns from customer_details table.