Set value for input field with children ()

I need to set the input value using the following method.

<table width="50%" border="0" id="pls-batting"> <tr id="1"> <td> <input name="in" type="text" value="5"> </td> </tr> <tr id="2"> <td> <input name="in" type="text" value=""> </td> </tr> </table> value = $("table#pls-batting tr:nth-child(1) td:nth-child(1)").children().val(); 

When I warn the value, it returns "5". This is good and good. Similarly, I need to set the value for the input field for the second row. I am using the following code

 $("table#pls-batting tr:nth-child(2) td:nth-child(1)").children().val='test'; 

But it does not work. Is there a way to set the value using the children() method or using the string id?

+4
source share
3 answers

Try it...

 $("table#pls-batting tr:nth-child(2) td:nth-child(1)").children().val('test'); 

or you can try another way

 $("table#pls-batting tr:eq(1) td:eq(0)").children().val('test'); 
+5
source

The .val() function is overloaded. If you just call .val() , you get the value of the input control. If, as if you are passing some parameter as .val("test") , jQuery will try to set the value for this input .

More on .val() in jQuery .

Hope you have a concept.

0
source

try this one

 $("table#pls-batting tr:nth-child(2) input").val('test'); 
0
source

Source: https://habr.com/ru/post/1395191/


All Articles