Welcome to WebmasterWorld Guest from 54.147.44.13

Forum Moderators: open

Message Too Old, No Replies

jquery selector syntax question.

     
8:21 pm on May 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:June 30, 2008
posts: 318
votes: 0


hi all,

I have a jquery selector defined in my javascript to load the contents of a table element. It appears to work but i'm not sure if the syntax is correct and might be causing me problems.

I'm trying to access a select tag in a table who's rows containing the select tag are dynamically appended to the empty tbody.

The table is defined as...

<table id="sa-table-2">
<tbody>

</tbody>
</table>



The javascript code is as follows...

// get all work order items.
for(i = 0; i < response.records; i++){
row = response.rows[i]; // row is cell array shortcut.

var id = row["cell"]["0"];

// append the select element row to the tbody.
$('#sa-table-2 tbody').append(
'<tr id="'+id+'"><td><select name="wi-PLID" class="wi-PLID"></select></td></tr>'
);

$(
'tr#'+id+' select[name="wi-PLID"]'
).load('php/script.php', data, function(data){$(
'tr#'+id+' select[name="wi-PLID"]'
).html(data.replace( blah blah blah ));});

}



Is the bolded selector definition correct for the bolded table row being appended?
10:02 pm on May 18, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


As long as id is unique, that should work, though the callback function sets this to the DOM element being operated on (which is the select element), so you're better off to use $(this) in place of the selector you're using in the callback so that it doesn't need to search for it again.
11:45 pm on May 18, 2012 (gmt 0)

Full Member

5+ Year Member

joined:June 30, 2008
posts: 318
votes: 0


thanks again.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members