Someone
Someone

Reputation: 10575

How to find the Row in the html table using jquery

Iam adding a new row on click of a button and that row contains 3 textboxes and one select buutton .How do I make the textboxes and select box values to null of that newly added row .

$('#table').find("sno_'+i'").val('');

Here "i " is dynamically generated row.But this is not working.

Upvotes: 0

Views: 495

Answers (2)

user113716
user113716

Reputation: 322452

If you're appending it as the last row and you want to clear all the form element value, you could just do this:

$('#table tr:last :input').val('');

If you need to limit it to the text and select inputs, do this:

$('#table tr:last').find(':text,:select').val('');

Beyond that, your question is not very clear. If i is the index of the row, then do:

$('#table tr').eq(i).find(':text,:select').val('');

If i has been appended to a class on the row, then do this:

$('#table tr.sno_' + i).find(':text,:select').val('');

If i has been appended to the ID attribute on the row, then do this:

$('#sno_' + i).find(':text,:select').val('');

Upvotes: 1

Don
Don

Reputation: 17606

Whatever it means, at first glance the +i should go outside quotes:

.find("sno_" +i)

Upvotes: 0

Related Questions