J'essaye d'analyser une donnée de réponse au format html. Les données contiennent plusieurs tables (pas de tables imbriquées). Je charge le html avec ajax et essaie de faire défiler les données avec jquery.Comment faire une boucle sur plusieurs tables avec jQuery dans un fichier html chargé avec ajax
Le problème est Aucun résultat quand je commence avec 'table' pour la boucle (j'ai plusieurs tables et n'ai aucun ID pour la table.) Quand j'utilise 'tr' Cela fonctionne bien dans Firefox et chrome mais pas dans IE.
Je voudrais savoir comment je peux parcourir ces tableaux. Voici le code que j'essayais.
<html>
<head>
<title>Html table tParser</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script language="JavaScript">
$(document).ready(function(){
$.ajax({
url: "htmltables.html",
cache: false,
success: function(html)
{
//alert((html.length));
//alert($(html).find('table').size());
$(html).find('table').each(function(index)
{
document.write('<br />'+'<br />'+ 'Table:' + index + '<br />')
$(this).find('tr').each(function(index) {
document.write('<br />'+'<br />'+ 'Row :' + index + '<br />');
$(this).find('td').each(function(index) {
document.write($(this).text() + '<br />');
}); //td
}); //tr
}); //table
} //success
}); // $.ajax(
});//$(document).ready(function
</script>
</head>
<body>
</body>
</html>
/*------------------------------ */
/* Here is the sample html file I was trying to parse*/
<html>
<head>
<title></title>
</head>
<body>
<table width="200" border="1">
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
</table>
<table width="200" border="1">
<tr>
<td>4</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>5</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</body>
</html>
beurk, formatez votre code! indentez-le 4 espaces s'il vous plaît! – Patricia