You can iterate over a group of divs or lis or whatever with JQuery.
The code below doesn't show the php, and it uses alerts to show what's going on with the JQery... I commented what would be the actual code.... hope it helps. Like this you don't have to worry about ids, since the order of items is what's important. You could of course leave the ids in.
Edit - added how to handle custom keys
Case 1: Numerical keys
<!DOCTYPE html>
<html lang="en">
<head>
<title>Binding events</title>
<script type="text/javascript" src="JQUERY-PATH/jquery-1.4.2.min.js"></script>
<meta charset="utf-8" />
<script type="text/javascript">
// When the page is ready ==================================================
$(document).ready(function()
{
$('li').each(function(index)
{
// The line below would read something like:
// $(this).click( function () {tag_search(index)});
$(this).click( function() { alert("This would trigger => tag_search(" + index + ")")});
});
});
</script>
</head>
<body>
The php goes into the unordered list:
<ul>
<li>zero</li>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<li>five</li>
</ul>
</body>
</html>
Case 2: Custom keys of your choice
If you have keys that are all numbers, you may want to stick an arbitrary letter in front, so that it validates for id or class names.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Binding events</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<meta charset="utf-8" />
<script type="text/javascript">
// When the page is ready ==================================================
$(document).ready(function()
{
$('li').each(function(index)
{
// The line below would read something like:
// $(this).click( function () {tag_search($(this).attr('id'))});
$(this).click( function() { alert("This would trigger => tag_search(" + $(this).attr('id') + ")")});
});
});
</script>
</head>
<body>
The php goes into the unordered list:
The custom keys are placed in ids or classes:
<ul>
<li id="Roger">zero</li>
<li id="Dodger">one</li>
<li id="23884">two</li>
<li id="Fubar">three</li>
<li id="Gungho">four</li>
<li id="Burlap">five</li>
</ul>
</body>
</html>
href="#"leads to nothing.