Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the next textarea using Jquery

HTML

<tr id="rowId"><td><textarea class="inputTextarea"></textarea></td><td><textarea class="inputTextarea"></textarea></td></tr>
<tr id="rowId2"><td><textarea class="inputTextarea"></textarea></td><td><textarea class="inputTextarea"></textarea></td></tr>
<tr id="rowId3"><td><textarea class="inputTextarea"></textarea></td><td><textarea class="inputTextarea"></textarea></td></tr>

Provided I know rowId, how do I find the next textarea ON THIS PAGE, starting at any arbitary point. I don't mean ANY input, textarea only. I need to be able to start AT ANY row, and progress on to the next textarea, essentially going down the rows.

EDIT Based on answers, I used the following code to traverse the textareas row by row:

var curElt = $('#' + startAt);  //startAt is the first row id   

        for(var i=1; i < 10; i++) {

            $(curElt).find('textarea').eq(0).val(i);
            $(curElt).find('textarea').eq(1).val(i+1);

            curElt = $(curElt).next();
        }
like image 748
sarsnake Avatar asked Jan 05 '11 01:01

sarsnake


2 Answers

You can use the next and find methods:

$('#' + current_row_id).next().find('textarea').eq(0);

next will get the next sibling, and then find will find all of the elements within the set that match the passed-in selector(s), then eq(0) will grab the first element in the resulting set returned from find.

like image 195
Jacob Relkin Avatar answered Nov 22 '22 07:11

Jacob Relkin


$('#rowId2').find('textarea');

That will find both children of the row. If you want the first one, either:

$('#rowId2').find('textarea').eq(0); //jQuery object
$('#rowId2').find('textarea')[0];    //DOM Element

Edit: If you only know one row and want to find the first textarea in the next row:

$('#rowId').next().find('textarea').eq(0);
like image 27
Phrogz Avatar answered Nov 22 '22 07:11

Phrogz