javascript - Select input tag in the same row from a table on clicking an anchor tag in the same row -


sample html(this contains 1 of many more row).

<table id="ctl00_contentplaceholder1_categorytable" class="categorytable sortasc editinputs" border="0">     <tbody>      <tr>      <td>8</td>      <td>      <input name="ctl00$contentplaceholder1$ctl17" type="text" value="307349_335692806541952_16061425_n.jpg" readonly="readonly" />     </td>     <td><input name="ctl00$contentplaceholder1$ctl18" type="text" value="key1 " readonly="readonly" /></td>     <td>3/28/2013</td>     <td>.jpg</td>     <td>28120</td>     <td><a href="download.aspx filename=307349_335692806541952_16061425_n.jpg&type=image">307349_335692806541952_16061425_n.jpg</a></td>     <td>     <a href="javascript:void(0)" class="editlinkclass">edit </a><a href="javascript:void(0)" class="deletetlinkclass"> delete</a><a href="javascript:void(0)" class="updatelinkclass" style="display:none;">update</a><a href="javascript:void(0)" class="cancellinkclass" style="display:none;"> cancel</a>     </td>     <tr>     </tbody> 

my javascript

$(document).ready(function () {             console.log("document ready")             $(".categorytable tr td a").click (function (event) {                 console.log($(this).text() + "click detected");                 if ($(this).text() === "edit ") {//compare "edit " not "edit"                     console.log("edit");                     console.log($(this).parent().parent().children('td input').text());                     $(this).siblings(".deletetlinkclass").attr("style", "display:none");                     $(this).siblings(".updatelinkclass").attr("style", "display:;");                     $(this).siblings(".cancellinkclass").attr("style", "display:;");                     $(this).attr("style", "display:none")                 }                 else                     console.log("no edit");             });         }); 

what trying select input tags in same row tr different td on click of anchor tag in same row. have tried lot of combinations of following jquery statement no success. please help. $(this).parent().parent().children('td input').text() here this represents clicked anchor tag. more clear don't want select input tags in table, ones in same row.

using parents() , find().

and value of input, use val() , not text() ..

$(this).parent().parent().children('td input').text();                                            //--^^^^^^---here   

try this

var inputs=$(this).parents('tr').find('input'); $.each(inputs,function(){  //<---- loop since have multiple input     console.log($(this).val()); //.val() since val() used input value.. }) 

or using closest()and find().

var inputs=$(this).closest('tr').find('input'); 

using context

var inputs = $('td input', $(this).closest('tr')).val(); 

working fiddle here


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -