I agree that it generates a lot of unnecessary work on the client side any
time someone clicks on a TD. It really was just a shot in the dark though. I
had an idea what I was doing, but the results were never going to be pretty.
Hey, throw enough spaghetti at the wall... ;)
dave.methvin 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/
>
>
--
View this message in context:
http://www.nabble.com/Wildcards-tf2299089.html#a6404049
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/