I am trying to retrieve a td using the “title” attribute value but cant seem to get it to work using the code example below:
var iframe = $("#iframe1");
var tr = iframe.contents().find("td[title='2015-02-06']").text();
alert(tr);
Below is the HTML source I’m testing the code against. Preferably I would like the code to use the table id as well in the selector as I have other tables in the iframe.
Any ideas please ?
<iframe id=iframe1>
<TABLE id=table1>
<TBODY>
<TR>
<TD title=2015-02-01>1</TD>
<TD title=2015-02-02>2</TD>
<TD title=2015-02-03>3</TD>
<TD title=2015-02-04>4</TD>
<TD title=2015-02-05>5</TD>
<TD title=2015-02-06>6</TD>
<TD title=2015-02-07>7</TD>
</TR>
<TR>
<TD title=2015-02-08>8</TD>
<TD title=2015-02-09>9</TD>
<TD title=2015-02-10>10</TD>
<TD title=2015-02-11>11</TD>
<TD title=2015-02-12>12</TD>
<TD title=2015-02-13>13</TD>
<TD title=2015-02-14>14</TD>
</TR>
<TR>
<TD title=2015-02-15>15</TD>
<TD title=2015-02-16>16</TD>
<TD title=2015-02-17>17</TD>
<TD title=2015-02-18>18</TD>
<TD title=2015-02-19>19</TD>
<TD title=2015-02-20>20</TD>
<TD title=2015-02-21>21</TD>
</TR>
</TBODY>
</TABLE>
</iframe>
iframe is supposed to embed
documentsbut notplainhtml. Put the html in some file suppose test.html and import that document in the iframe then you selector will bring the contents.The IFRAME element allows authors to insert a frame within a block of text. Inserting an inline frame within a section of text is much like inserting an object via the OBJECT element: they both allow you to insert an HTML document in the middle of another, they may both be aligned with surrounding text, etc, You can read more over w3.org
You can check the working of your selector here