Hi again Edward.
You are very lucky that your JSFIDDLE worked. Your example uses very basic jQuery methods and the "luck" is that because your example makes use of events, the JavaScript (hence jQuery) event handler is passed the actual element that fired the event. In your chosen example the element could have been totally anonymous and the code still have worked.
Typical power uses of jQuery will need to iterate elements. I have created a JSFIDDLE to do so, here...
http://jsfiddle.net/alano/y3Mjf/ . As you will see, the use of non-unique ID's causes catastrophic failure. jQuery only sees and processes the first element. As a comparison, to demonstrate jQuery "best practice", I have included a second implementation containing ZERO id values on the recurring elements, which works just fine.
Your thought process is correct. You are trying to find a mechanism within the HTML markup scheme to identify elements requiring a special treatment. The problem is that you have a chosen the wrong mechanism. If you read any jQuery reference guide, tutorial or manual, you will learn that the method designed and designated by the jQuery team for this purpose is the "pseudo-class", not the "id" attribute.
A "pseudo-class" is simply a class name that ordinarily has no CSS styling definitions associated with it. Often, though, developers will kill two birds with one stone and use a class name as both a jQuery selector and a CSS styling tag.
The next step up from this is, as I mentioned in my earlier post here, you need to convert your customisation code into "plugins" and apply them to your code using pseudo-classes as selectors.
I apologise in advance if you believe in the following text I am talking out of turn. It is my strongest desire to help people make better use of jQuery. I certainly do not wish to be negatively critical of anyone.
I suspect you are still fairly new to jQuery. I too, when I started jQuery, did not "get" how jQuery can be used so very differently to plain JavaScript. My first jQuery scripts were more-or-less just straight translations of JavaScript into jQuery. For example, I would often simply change document.getElementByID("IDvalue1") into $("#IDvalue1").
I was really missing the "point" and power of jQuery.
Much of jQuery's power is achieved by its hierarchical traversal and manipulation methods. One perfect demonstration of this is when a jQuery Forum User wished to create an on-screen calendar with a column for each day of the month, and rows for quarter-hours "slots" covering office hours. In their initial implementation they literally gave each table cell, each row, each heading, EVERYTHING, an "id" value so that when a user clicked anywhere the code could easily determine the day and time of slot. Furthermore, the html was blighted by extensive styling attributes too. It was quite "intense".
Their implementation didn't use non-unique id values, but my "point" is still the same... jQuery makes clever and easy use of "relational" operators throughout - meaning that you need only the barest of HTML markup, and virtually zero id values.
In the dozen or so lines of code in my version of the calendar, I programmatically generated the table's HTML markup, the <thead><th> cells (header row) were each given a custom data attribute containing the date, the <tbody><th> cells (first column) were each give a custom data attribute containing the from-until times. None of the 30 X 40 inner <tbody><td> cells contained any text, attributes, or styling attributes. The inner cells were just "<td>" and nothing else (not even a closing tag is required for <td>'s).
When a user clicked one of the inner cells, a single line of jQuery would traverse the HTML to find the matching <tbody><th> and thus obtain the timeslot from the custom data attribute, plus in the same line of code an indexed traversal through the <thead><th> would obtain the matching date. The HTML markup looked naked, but with the power of jQuery, id values are rarely needed, so it really looked bare!
There's also a strong parallel between jQuery and any accompanying CSS style definitions. By design, jQuery shares the same hierarchical selectors as CSS. In the Forum User's version of the calendar, which used hard-coded HTML, every cell, including the header, first column, and body, contained CSS markup too. Like powerful jQuery code, the CSS styling does not need to reference id values within the HTML. The CSS definitions should be within a <style> tag (and/or in its own file) and defined using relative (hierarchical) references.
Sorry for blathering on. I'm simply keen that you do discover the "power" of jQuery. If you are relying upon "id" values then you are probably missing the "point" (and power) of jQuery.
Perhaps I have completely misunderstood your usage of jQuery, in which case I humbly apologise.
Kindest regards,
Alan