homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

jquery selector syntax question.

5+ Year Member

Msg#: 4455122 posted 8:21 pm on May 18, 2012 (gmt 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">


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?



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

Msg#: 4455122 posted 10:02 pm on May 18, 2012 (gmt 0)

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.


5+ Year Member

Msg#: 4455122 posted 11:45 pm on May 18, 2012 (gmt 0)

thanks again.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved