Tutorial :How to find an element by classname in another cell in a table row?



Question:

From the change event of a textbox in a td, I want to find a div whose classname = 'licenseStatus' in another cell within the row in which the textbox resides but can't seem to figure it out...

$('#gridRequestedApps .xxxAppName').change(function() {     var licenseOutputCell = $(this).parent('tr').find(".licenseStatus");     alert(licenseOutputCell.text());    // is an empty string  });  


Solution:1

You may need to use the parents() function:

$("#gridRequestedApps .xxxAppName").change  (    function()    {      var licenseOutputCell = $(this)                                .parents("tr:first")                                .find("div.licenseStatus");      alert(licenseOutputCell.text());    }  );  

parents("tr:first") works because you're selecting the first TR ancestor element, and not a direct parent which is what parent() does.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »