tags:

views:

33

answers:

3

Hi;

Jquery Code:

$("[id$=mytable] tr").click(function() {

    alert($(this).html());

});

Html:

<table id="mytable">

    <tr>
      <td class="locked">1</td>
      <td>2</td>
      <td>3</td>      
    </tr>
    <tr>
      <td class="locked">a</td>
      <td>b</td>
      <td>c</td>      
    </tr>      
  </table>

ı need only "td class='locked'" click return this

click: <td class="locked">1</td>

output:

<tr>
      <td class="locked">1</td>
      <td>2</td>
      <td>3</td>      
    </tr>
A: 

I originally had a solution much like the others here, that is, to bind the callback to the td.locked. I guess you really want to bind it to the tr and only output the td.locked, so here is my version:

$("#mytable tr").click(function() {

    alert($(this).find("td.locked").html());

});
Daren Thomas
Other way round, click (bind) to the TD, and output the contents of the TR
Mailslut
+1  A: 
$('table#mytable tr td.locked').click(function() {
    alert($(this).parent().html());
});
Mailslut
thank you work.
Oraclee
@oraclee, if you're happy with the answer, could you please "accept" it?
Mailslut
don't just thank him (her?). Upvote Mailslut and accept the answer ;)
Daren Thomas
@Daren Thomas 10 minutes wait :S
Oraclee
+2  A: 

I created a demo for you here

$(function(){
  $('td.locked').click(function(){
   var html = $(this).parent().html();
   alert('<tr>' + html + '</tr>');
  });
});
Sarfraz
@sarfraz thank you work
Oraclee
@oraclee: You are welcome.............
Sarfraz