jquery - Javascript store table in a variable with conditions -
this how page looks like:
<div class="bgsmtitle smtitle">customer addresses</div> <table class="bglttable"> <tr> <td class="bgltrow1 padded">new york</td> </tr> <tr> <td class="bgltrow1 padded">osaka</td> </tr> <tr> <td class="bgltrow1 padded">los angeles</td> </tr> </table> <div class="bgsmtitle smtitle">family members</div> <table class="bglttable"> <tr> <td class="bgheader1 padded" style="width:24%;">name</td> <td class="bgheader2 padded" style="width:10%;">relationship</td> <td class="bgheader1 padded" style="width:30%;">age</td> </tr> <tr> <td class="bgltrow1 padded">jordan</td> <td class="bgltrow2 padded">father</td> <td class="bgltrow1 padded">58</td> </tr> </table>
i store tables class name bglttable
. these table can appear 3-4 times in page. possible specific table using div above it? like:
var tableaddress = div.innerhtml="customer addresses".table.bglttable; var tablemembers = div.innerhtml="family members".table.bglttable;
var customeraddressestable = $('div.smtitle:contains("customer addresses")').next('.bglttable'); console.log($("<div />").append($(customeraddressestable).clone()).html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr class="prnt"> <td> <div class="bgsmtitle smtitle">customer addresses</div> <table class="bglttable"> <tr> <td class="bgltrow1 padded">new york</td> </tr> <tr> <td class="bgltrow1 padded">osaka</td> </tr> <tr> <td class="bgltrow1 padded">los angeles</td> </tr> </table> </td> </tr> <tr class="prnt"> <td colspan="3"> <div class="bgsmtitle smtitle">family members</div> <table class="bglttable"> <tr> <td class="bgheader1 padded" style="width:24%;">name</td> <td class="bgheader2 padded" style="width:10%;">relationship</td> <td class="bgheader1 padded" style="width:30%;">age</td> </tr> <tr> <td class="bgltrow1 padded">jordan</td> <td class="bgltrow2 padded">father</td> <td class="bgltrow1 padded">58</td> </tr> </table> </td> </tr> </table>
this method give html of required table.
Comments
Post a Comment