Monday 15 February 2010

javascript - jQuery selector not on id -



javascript - jQuery selector not on id -

i trying create selector in jquery attempts failed. can help me? have table this

<tr> <td>1</td> <td><input id="amonttuy1diam" class="selectdiam"></td> <td><input id="amonttuy1long" class="selectlong"></td> <td><select class="matselectlist" id="amonttuy1type"> <option value="0"> </option> <option value="7">value 1</option> <option value="8">value 2</option> </select></td> <td><input id="amonttuy1rugo" class="selectrugo"></td> </tr>

and have action on alter of select list , want alter value of input in lastly td without accessing id.

$(".matselectlist").change( function() { $(this).closest('tr').find(':last-child').val('test'); //doesn't work });

i can't access id because alter function executed on class, , have several table type of alter value do. idea

you're trying set val of td, need select input:

$(this).closest('tr').find('td:last input').val('test');

class="snippet-code-js lang-js prettyprint-override">$(".matselectlist").change( function() { $(this).closest('tr').find('td:last input').val('test'); //does work }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tr> <td>1</td> <td><input id="amonttuy1diam" class="selectdiam"></td> <td><input id="amonttuy1long" class="selectlong"></td> <td><select class="matselectlist" id="amonttuy1type"> <option value="0"> </option> <option value="7">value 1</option> <option value="8">value 2</option> </select></td> <td><input id="amonttuy1rugo" class="selectrugo"></td> </tr> </table>

javascript jquery html

No comments:

Post a Comment