# Sunday, January 26, 2014

In the last article, I showed how to use jQuery to select elements in the Document Object Model (DOM) of a web page. In this article, I will show things you can do with those selections.

Calling Methods on Selections

We can call methods on the list of objects returned by a selection simply by appending a dot, followed by the method call and any arguments to the selection syntax. For example, the following jQuery will hide all the anchor tags on a page:


Binding Functions to Selections

One of the powers of jQuery is the ease with which we can bind a function to the events of an object, so that this function executes whenever the event fires. To do so, simply append a selection with a dot followed by the name of the event; then, pass the function as an argument to the event, as shown below:


For example, the click event fires when a user clicks on a page element. The following sample binds a function to the click event of an element with the ID “Div1”:


The (document).ready event

The document variable is defined within the jQuery script. Selecting this variable with $(document) will return the document as a whole. The most common use for this selector is to bind a function to the document’s ready event. The syntax for this is


I have omitted the body of the function in this case, but notice the anonymous function declaration. In JavaScript, we don’t need to assign a name to a function if we are binding it to an event – we only need to pass that function to the method name. This is common syntax in JavaScript.

In fact, binding a function to the document ready event is so common, that its syntax can be shortened to simply surrounding a function with parentheses preceded by “$”, as shown in the following snippet, which does the same thing as the previous snippet


Putting it All Together

We can nest functions in jQuery and we often do so by binding code to events when the document.ready event fires, as in the following example:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">

In this article, I showed how to manipulate selected elements and bind events to those elements. This can be done when a page loads by adding code to the document.ready event.

Sunday, January 26, 2014 5:00:00 PM (GMT Standard Time, UTC+00:00)
# Saturday, January 25, 2014

How JavaScript Interacts with a Web Page

When a web page loads in a web browser, the browser loads all elements into memory. Each element on a page exists in a containership hierarchy – that is, each element is contained within another element with the document itself at the top of this containership hierarchy. Containership is defined by tags that are opened and closed between the opening and closing tags of another element. For example, the simple page in the listing below is loaded into memory in an object graph similar to that shown in Figure 1.

    <title>My Page</title>
       src="http://code.jquery.com/jquery-1.7.1.min.js ">
          This a <a href="Page2.htm">link</a>

Fig. 1

jQuery keyword

Because jQuery is JavaScript, it can be mixed with native JavaScript in your script files. The jQuery object is defined in the jQuery file and you can use it via the “jQuery” keyword. This keyword tells the parser that what follows is jQuery syntax. This keyword is so common that it can be shortened to the simpler “$”.

“$” is used to define selectors and to call methods defined in the jQuery scripts.


Most of what you will do with jQuery involves selecting a set of objects and performing some action on those objects, such as

· Changing the properties of each object in the set

· Binding code to an event of the objects

· Calling a method on each object

You can return a set of objects with the following jQuery syntax:


where selector is a snippet identifying which objects to select. The syntax of a jQuery selector is similar to the syntax for a CSS selector. The most common selectors are for a tag, and ID, and a Class Name, as shown in the list below.


Select by…






Class Name



Element Type



Variable Name


A selector preceded by “#” will be interpreted as an ID selector. jQuery will search the page for any element that matches the ID that follows “#” in the selector.

A selector preceded by “.” will be interpreted as a Class selector. jQuery will search the page for any element assigned the name of the Class that follows “.” in the selector.

A selector with no preceding characters will be interpreted as a Tag selector. jQuery will search the page for any element with the tag name identified in the selector.

Advanced Selectors

Combining Selectors

It is possible to combine selectors to either narrow your selection or establish containership.

Two selectors separated by a space indicate that jQuery should select the second selector only if it is found within the first selector. For example, $(“div a”) selects every anchor tag that is contained within a div tag.

Two selectors concatenated without a space indicate that jQuery should select only objects that match both selection criteria. For example, $(“div.BodyText”) selects any div tag that contains the attribute class=”BodyText”.

Set-based Selectors

By default, jQuery selectors always select a set of elements, even if that set may contain zero, one, or more than one element. However, we can refine a selection further by appending filters to a selection, such as “:first”, to select only the first element in the selected list of elements; “:last”, to select the last element in the selected list; “:even”, to select only the even-numbered elements; and “:odd”, to select only the odd-numbered elements. When even and odd selectors, it is important to note that the sets start with index number 1.

For example, $(“div:first”) selects the first div on the page, while $(“a:even”) selects every other anchor on the page, beginning with the second.

In this article, I described how to select objects on a web page with jQuery. In the next article, I will show things that we can do with those selections.

Saturday, January 25, 2014 5:56:00 PM (GMT Standard Time, UTC+00:00)
# Friday, January 24, 2014

Accessing jQuery From Your Site

To start using jQuery, simply add a reference to the jQuery library as in the following example:


Of course, you will need to download jQuery from http://jQuery.com and save it in your site’s scripts folder for the location above to work. Also, the currently downloaded version may have a slightly different name as the version number is included in the file name.

Using a Content Delivery Network

Alternatively, you can connect to jQuery on a Content Delivery Network (CDN), such as one provided by jQuery, Microsoft, or Google, in the following manner:





  src="http://code.jquery.com/jquery-1.10.2.min.js ">

A CDN offers the following advantages:

  1. A CDN has servers around the world, so it can serve up files closer to the client that requested them, so they download faster.
  2. Most web clients cache files by default, so the client may already have a cached copy of the jQuery script file and may not need to download it again.

Adding jQuery to your site or page is simple and fast. In my next article, I will talk about the syntax of jQuery and how to use it to select objects on a web page.

Friday, January 24, 2014 5:42:00 PM (GMT Standard Time, UTC+00:00)
# Thursday, January 23, 2014

I began to write web applications in the 1990s and, from the beginning, I understood that client-side scripting would enhance my applications. If I wanted to update part of a web page, client-side scripting could do so quickly and elegantly and without sending a new request to the server or refreshing the entire page and I knew it.

JavaScript quickly became the de facto language of the web and, unfortunately, I was never very good at JavaScript. One reason I struggled with JavaScript was because each browsers implemented JavaScript in its own way and sometimes the language diverged from one browser to the next. For example, the following JavaScript code is necessary to perform the simple task of retrieving an element from a web page:

var id = "Div1";
var elm = null;
  if (document.getElementById)
    elm = document.getElementById(id);
  else if (document.all)
    elm = document.all[id];
  else if (document.layers)
    elm = document.layers[id];

Notice there are several different JavaScript commands that retrieve an element by its ID. Some commands work in some browsers, but not in others. The code snippet above has to test the validity of each command until it settles on one that works within the current browser.

This simple task is complicated by the different JavaScript engines.

Eventually, I discovered jQuery and the problem of cross-browser client-side program went away. jQuery is a JavaScript library that allows a developer to write code that works across disparate browsers, without the necessity of trying multiple commands. The jQuery core library takes care of the different JavaScript implementations. For example, the code above is simplified in jQuery to

var elm = $("#Div1");

This is a simple task, yet it underscores the terseness and simplicity of jQuery. All the cross-platform code is abstracted away when I use jQuery, making my JavaScript much easier to read and maintain.

Thursday, January 23, 2014 5:37:00 PM (GMT Standard Time, UTC+00:00)
# Wednesday, January 22, 2014

It was a little over five years ago in Sandusky, OH. I was attending Codemash - a conference that had yet to become as famous as it is today - and I had brought a video camera with me. My plan was to interview conference attendees on camera - asking them about a favourite technology or a project of which they were particularly proud. The first person who agreed to an interview was Steve Smith. Steve was delivering a talk later in the day on performance and scalability, so we talked about that. It went really well and gave me confidence to interview a few more people. I discovered that John Kellar also brought a video camera and was involved in a similar project. He had already released a couple episodes, so I interviewed him about his strategies for producing his show. It took me almost a month before I was able to edit the videos and produce something worth sharing. Originally, I posted them to my blog; but within a year, I had registered the TechnologyAndFriends.com domain and moved all episodes over to that site. 

I elected to make John’s interview Episode 1 because that served as a good intro to the show.

I’ve made a few changes to the format over the years: The show tends to be a little longer now than the first few episodes, some of which were under 5 minutes; I’ve created a couple different intros and outros for the show over the years; and I’ve experimented with the show’s music, now settling on an open source song recorded by DJ Cline, which I like and which won’t tempt copyright lawyers.

Last week, I published Episode 300, which featured clips from the previous 99 episodes. I marked episodes 100 and 200 with similar montages.

I’m proud to see the show last as long as it has; I’m proud that people still watch and tell me they enjoy it; I’m proud of the outstanding guests I’ve been able to persuade to appear on the show. I’ve learned enough over the years to improve the quality of the show – I’m better able to think on my feet and ask follow up questions, and I’ve bought much better audio equipment and become more proficient at my editing tools. One thing I’m particularly proud of is that I have released a new episode every week for the last 2 years. I believe this consistency is important in order to maintain a regular viewership.

I can’t predict how long I will continue this project, but my hope is it will be at least another 5 years and at least another 300 shows.

If you are a regular viewer, I thank you. If you are unfamiliar with the show, I welcome you to check it out at http://technologyandfriends.com.


Wednesday, January 22, 2014 4:40:52 PM (GMT Standard Time, UTC+00:00)
# Tuesday, January 21, 2014
Are We There Yet? displays a list of popular vacation destinations, organized by destination type, such as national parks, cities, and attractions. Drill down into each destination to learn more about traveling there. The app also includes travel tips, and uesful links such as directions and weather. This is a small app, but useful if you are planning a vacation. You can download Are We There Yet? at this link.
Tuesday, January 21, 2014 8:47:16 PM (GMT Standard Time, UTC+00:00)
# Monday, January 20, 2014
Monday, January 20, 2014 10:22:00 PM (GMT Standard Time, UTC+00:00)
# Monday, January 13, 2014
Monday, January 13, 2014 10:21:00 PM (GMT Standard Time, UTC+00:00)
# Wednesday, January 8, 2014

With the help of others in the developer community, Rob Gibbens hosted a Windows 8 / Windows Phone development hackathon. Despite the winter storm, over 2 dozen developers showed up and submitted 17 apps. Here are a few of the apps created that day:

Windows 8 Store apps

Text Adventure RT

Tells a bit of an adventure story; then, asks the reader what to do next. The next bit of the story depends on the reader's choice.

CHRISTmas Music Videos

A collection of music videos featuring Christmas music played by Christian artists.


An RSS reader that allows you to categorize your feeds

This app allows the customers ofJenptik Industrial Metrology North America designs (JIMNA) to view items in their system. One needs a username and password to use this app.


This app allows the customers ofJenptik Industrial Metrology North America designs (JIMNA) to view items in their system. One needs a username and password to use this app.

SportsTube – Michigan State Football


A collection of videos of the storied MSU football team.


Remember When


This app allows you to keep track of the last time you did something, such as changing your oil or getting a hair cut. It costs $.99 but there is a free trial.

Apps | Phone | Windows8
Wednesday, January 8, 2014 4:09:00 AM (GMT Standard Time, UTC+00:00)
# Tuesday, January 7, 2014
Tuesday, January 7, 2014 11:25:31 AM (GMT Standard Time, UTC+00:00)