Skip to main content

jquery match element based on id



I'm a noob to jquery. Stuck and would appreciate some help. Currently building a tool to grab data from a particular page. The page looks like this:







<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">

<tbody> //This is data group 1

<tr id="parent0"> //Record 1

<td align="left"> <---------- text1 here -------> </td>

<td align="left"> <---------- text2 here -------> </td>

<td align="left"> <---------- text3 here -------> </td>

</tr>

<tr id="parent0"> //Record 2

<td align="left"> <---------- text1 here -------> </td>

<td align="left"> <---------- text2 here -------> </td>

<td align="left"> <---------- text3 here -------> </td>

</tr>

</tbody>

</table>



<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">

<tbody> //This is data group 2

<tr id="child0"> //Record 1

<td align="left"> <---------- text1 here -------> </td>

<td align="left"> <---------- text2 here -------> </td>

<td align="left"> <---------- text3 here -------> </td>

</tr>

<tr id="child0"> //Record 2

<td align="left"> <---------- text1 here -------> </td>

<td align="left"> <---------- text2 here -------> </td>

<td align="left"> <---------- text3 here -------> </td>

</tr>

</tbody>

</table>







Below is a snippet of the jquery:







ancestor = $(this).closest("tr[id]");



matchedElement = $(this).first();

originalBgColor = $(matchedElement).css('background-color');

$(matchedElement).css('background-color', 'green');

$(matchedElement).bind('click.annotator', function(event) {

event.stopPropagation();

event.preventDefault();

self.port.emit('show',

[

document.location.toString(),

$(ancestor).attr("child0"),

$(matchedElement).text()

]







I'm trying to capture all data from just the <tr> blocks with id parent0, and child0.





In it's current working state, the tool captures all data within the two tables as text. Ideally I'd like to be able to capture all the <TR> blocks separately, put them in an array that I can then iterate over.


Comments

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...