jquery - how to find a sibling cell using class names?
I have table that's generated by looping through data, like this:
    $.each(array_rule_segments, function(key, listofwidgets) {
         //console.log('in outer loop');
         var widget_details = listofwidgets.split(',');
             var counter = key + 1
         htmlstring += '<tr id="listofwidgets_' +  key + '">';
         htmlstring += '<td><input type="button" value="Remove"
class="remove"/></td>';
         htmlstring += '<td name="widget_type" class="widget_type"
id="widget_type' + counter + '">' +  widget_details[0] + '</td>';
         htmlstring += '<td name="widget_details" class="widget_details" 
id="widget_details' + counter + '">' + widget_details[1] +
'</td>';
         htmlstring += '<td name="widget_order" class="widget_order"
id="widget_order' + counter + '">' + widget_details[2] + '</td>';
         htmlstring += '<td name="messages" id="messages' + counter + '">'
+ widget_details[3] + '</td>';
         htmlstring += '</tr>';
});
Then later on, I have logic that checks to see if the new widget the user
is trying to add to the table already exists. For example, let's say I
have a widget already in the table with a value of "1234" in the
widget_details field.
I check for that like so:
 $("#add_to_table").live("click", function()   {
     var cell;
 var result = $('#summary_table tr').find('td:contains('+
$('#input_widget_details').val() +')'); //find cell in table with same
widget dteails information...
if (result.length > 0 ) {
    //check for duplicates using class names.
        console.log(result.siblings(".widget_order").html());
    if (result.siblings(".widget_order").html() ==
$('#widget_order').val() && result.siblings(".widget_type").html() ==
$('#widget_types').val()){
        alert("Duplicate rule segment!");
        return false;
    }
}
The first if statement works... it finds the row that has the matching
widget details value... but I'm not able to check the sibling cells based
on their class names. the debug statement i have where I'm trying to check
the html() on the sibling yields a value of null. I've also tried .val()
instead of .html().
Any suggestions on where I'm going wrong?
Thanks.
 
No comments:
Post a Comment