Personally, i use things with IDs like title_<number> and stuff like that all the time, and $("[EMAIL PROTECTED]'title_']") seems to work fine. I havent had any problems.

On 9/19/06, Dave Methvin <[EMAIL PROTECTED]> wrote:

> Here is another approach which actually detects all td clicks...
>
> $("td").click(function(){
>
>  //If the td ID length is greater than 12...
>  if ($(this).id().length >12){
>
>    //If the first 12 chars of the ID = td_comments_...
>    if ($(this).id().substring(0,12) == "td_comments_")
>    {
>      /* Your onclick event for td_comments_ goes here */
>    }
>  }
>});

Depending on how many td_comments_* elements were in the table, that could
create a lot of unneeded handlers though. It would definitely be better to
attach them only to the elements that needed them. Also, since the "this" is
a DOM element it would be much more efficient to use it natively rather than
convert it to jQuery, by saying this.id instead of $(this).id().

Are all the td_comments_* elements in the same column of the table? If so
you should be able to use a colgroup/col and attach a class to the col
corresponding to that column. Then use a standard ".class" selector to
attach the events.

Is every element assigned some unique id? If so you might be able to make
the document much smaller by assigning an id to the row only and then using
the DOM parent id to determine the row when a td is clicked.

Here's what I mean, untested:

$("#ratings .comment).click(function(){
  var row = +this.parentNode.id.substr(3); // Number
  /* your code here... */
});

<table id="ratings">
<tr>
  <th>Name</th><th>Type</th><th>Comment</th>
</tr>
<colgroup><col span="2"><col class="comment"></colgroup>
<tr id="row01">
  <td>Joe</td><td>Smooth</td><td>Knows his way around</td>
</tr>
<tr id="row02">
  <td>Bob</td><td>Silly</td><td>Talks a tough game</td>
</tr>
<tr id="row03">
  <td>Hans</td><td>Smart</td><td>Part of the "in" crowd</td>
</tr>
</table>


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to