Jquery Insérer un élément avant de l' <tr>
J'essaie d'insérer un élément de bloc Insérer quelque chose avant l'autre . Je ne suis pas sûr si j'utilise la bonne méthode, mais voici mon code. Espérons que vous les gars peut vous aider. Merci!
Jquery
$("#addMatch").click(function(){
$("<td>New insert</td>").insertBefore("#addMatch").closest('tr');
return false; //this would insert the <td>New insert</td> before the
//<td><input type="button" id="addMatch" name="addMatch" value="Add
//Match" </td> but not <tr>
});
Html
<tr>
<td>some data</td>
</tr>
//can't tell how many tr would show before the last "addMatch" button. It's dynamic.
//I want the <td>New insert</td> show up here.
<tr>
<td><input type="button" id="addMatch" name="addMatch" value="Add Match" </td>
</tr>
Vous devez vous connecter pour publier un commentaire.
<td>
doit toujours être dans un<tr>
.Je serais probablement faire de votre fonction comme ceci:
.parents('tr:first')
, il y a.closest('tr')
🙂