This is going to be a standard practice you're going to learn through writing HTML over and over, time and time again! A good way to avoid using duplicate ID's would be to use less ID's and maybe use classes in their place.
Only use ID's for important/structural elements on your website such as #header
, #footer
, #main
, #slideshow
, #content
, #sidebar
, etc.
If you're repeating ID's over and over on a page maybe you should be using classes. Any element/styled module that is going to be reused on that a multiple times should be identified using a class.
Also, some IDE's will perform some special syntax highlighting/text-decoration to let you know that something funky is going on. Two that come to mind immediately are SublimeText2 and Visual Studio.
Here's a jQuery snippet you can run to check for duplicate ID's on a page. It will let you know in your Console (F12 developer tools/Firebug) if there are any duplicates on the page.
(function () {
var found = false;
$('[id]').each(function () {
var ids = $('[id=' + this.id + ']');
if (ids.length > 1 && ids[0] === this) {
console.warn('ID used more than once: ' + this.id, ids);
found = true;
}
});
if (!found) {
console.log('No duplicate IDs found');
}
})();
You could throw this in your global footer so that it runs on every page, just be sure you take it out before going to production.
Here's a JSFiddle: http://jsfiddle.net/A7h75/
Got the script from here.