jQuery 1.6 is now available for download!
jQuery CDN:
Microsoft Ajax CDN:
You can read more about this on the following link: http://blog.jquery.com/2011/05/03/jquery-16-released/
Code snippets and technology news that come across my daily life.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Part2._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script src="jquery-1.3.2.js" type="text/javascript"></script> <style type="text/css"> .horizontal { float: left; list-style: none; margin: 10px; } </style> </head> <script type="text/javascript" language="javascript"> </script> <body> <form id="form1" runat="server"> <ul id="os"> <li>Windows <ul> <li>DOS</li> <li>Win 95</li> <li>Win 98</li> <li>Win ME</li> <li>Win XP</li> <li>Win Vista</li> <li>Win 7</li> </ul> </li> <li>Unix <ul> <li>Unix</li> <li>Solaris</li> <li>Linux</li> </ul> </li> </ul> </form> </body> </html>
<script type="text/javascript" language="javascript"> $(document).ready(function() { $('#os > li').addClass('horizontal'); }); </script>
$('#os li:not(.horizontal)').addClass('sub-level');
.sub-level { background-color: Yellow; }
$('div[@width]')$('div[table]')$('a[@href^="mailto:"')The above statement will get all anchor tag with attribute href starts with mailto$('a[@href$=".aspx"')$('a[@href*="domain"')Above query will find all anchor tags with href attribute containing the string domain anywhere.$('div.horizontal:eq(0)')
Since CSS index is one based, in CSS selector we must use 1 to get the 1st element.<table> <tr> <td> SomeData1 </td> <td> SomeData2 </td> </tr> <tr> <td> SomeData3 </td> <td> SomeData4 </td> </tr> <tr> <td> SomeData5 </td> <td> SomeData6 </td> </tr> <tr> <td> SomeData7 </td> <td> SomeData8 </td> </tr> <tr> <td> SomeData9 </td> <td> SomeData10 </td> </tr> </table>
<style type="text/css"> .odd-style { background-color: Olive; } .even-style { background-color: Aqua; } </style>Now let’s see how jQuery can apply those styles to the table.
<script type="text/javascript" language="javascript"> $(document).ready(function() { $('tr:odd').addClass('odd-style'); $('tr:even').addClass('even-style'); }); </script>
$('td:contains("somedata4")').addClass('bold');
$('tr').filter(':odd').addClass('odd-style');This is another way to traverse the DOM and the impact is same as the statement we used for applying odd-style in previous scenario. I am going to add headers to our table by placing the following to the beginning of the table element.
<tr> <th>Column1</th> <th>Column2</th> </tr>
$('th').parent().addClass('heading-style'); $('tr:not([th]):even').addClass('even-style'); $('tr:not([th]):odd').addClass('odd-style'); $('td:contains("SomeData3")').addClass('bold');1st statement will get the parent of ‘th’ which will be the 1st tr and apply the style heading-style
$('td:contains("SomeData3")').next().addClass('bold');
$('td:contains("SomeData3")').siblings().addClass('bold'); $('td:contains("SomeData3")').parent().find('td:gt(0)') .addClass('highlight'); $('td:contains("SomeData3")').parent().find('td').not(':contains("SomeData3")')).addClass('bold'); $('td:contains("SomeData3")').parent().find('td:eq(1)').addClass( 'bold').end().find('td:eq(2)').addClass('bold');
$('td:contains("SomeData3")') //get every cell containing "SomeData3" .parent() //get its parent .find('td:eq(1)') //find inside the parent the 2nd cell .addClass('bold') //add the "bold" class to that cell .end() //revert back to the parent of the cell containing "SomeData3" .find('td:eq(2)') //find inside the parent the 3rd cell .addClass('bold'); //add the "bold" class to that cell
var myTag = $('#myId').get(0).tagName; var myTag = $('#myId')[0].tagName;
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Part1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script src="jquery-1.3.2.js" type="text/javascript"></script> <style type="text/css"> .oldstyle { margin: 0 2em; } .newstyle { font-style: italic; border: 1px solid #888; padding: 0.5em; color:Red; } </style> </head> <script type="text/javascript" language="javascript"> $(document).ready(function() { $('.oldstyle').addClass('newstyle'); }); </script> <body> <form id="form1" runat="server"> <div> <h1> Part 1</h1> <div> by Amal Hashim </div> <div class="oldstyle" id="part-1"> Easily traverse the DOM without writing large chunks of JavaScript. Helps to change the CSS even after the page has been rendered. Easily alter the page content with minimal code. Efficient event handling. Animations to the page. Integrated with AJAX. JavaScript tasks such as array manipulations and iterations. Multiple actions in one line of code. Library file size is minimal. </div> </div> </form> </body> </html>
In this article I am going to explain, how we can use JQuery for preparing a slid show using various images. You can download JQuery from the following link.
Below is the aspx page content
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Image slide show</title>
<script type='text/javascript'
src="JQuery/jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
$(function() {
var img = $("img.imgclass");
$(img).hide().eq(0).show();
var cnt = img.length;
setInterval(imgRotate, 5000);
function imgRotate() {
$(img).eq((img.length++) % cnt).fadeOut("slow", function() {
$(img).eq((img.length) % cnt)
.fadeIn("slow");
});
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<img src="Images/1.jpg" class="imgclass" alt="Image1"/>
<img src="Images/10.jpg" class="imgclass" alt="Image2"/>
<img src="Images/11.jpg" class="imgclass" alt="Image3"/>
</form>
</body>
</html>
In the code what I am doing is straight forward. Get all img tags with class “imgclass”. Hide them initially. Every 5 second, call the method “imgRotate”. This method will fadeout the previous image and fade in the current image. Inside the form tag, you can add as many images you needed.
Hope this was helpful