Chicharito
Chicharito

Reputation: 1440

Jquery Select Problem

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>

Upvotes: 0

Views: 62

Answers (3)

Sarfraz
Sarfraz

Reputation: 382616

I created a demo for you here

$(function(){
  $('td.locked').click(function(){
   var html = $(this).parent().html();
   alert('<tr>' + html + '</tr>');
  });
});

Upvotes: 2

Dal Hundal
Dal Hundal

Reputation: 3324

$('table#mytable tr td.locked').click(function() {
    alert($(this).parent().html());
});

Upvotes: 1

Daren Thomas
Daren Thomas

Reputation: 70314

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());

});

Upvotes: 0

Related Questions