htmlに特定の文言が存在する場合に、最も近いテーブルを削除する操作を行いたい。
そこにスパンクラスが存在するとは思いません。htmlは反対側から取得されるため、いつでもクラスを追加、削除することで変更される可能性があります。
内部のclass/idイベントがクリックされたときではなく、ページの読み込み時に実行する必要があります。
ちょっとやりがいがあります。これを達成する方法はありますか?
ページの読み込み時に、
「Hellohowareyou」がページに存在するかどうかを検出するjquery。
If exist
remove the whole td or tr or table for this particular.
else
do nothing.
end
以下のようにコーディングします。
function replaceText()
{
var debug;
debug= "";
$("*").each(function() {
if($(this).children().length==0)
{
// $(this).text($(this).text().replace('Hello how are you', 'yohoo'));
debug= debug + $(this).val() + "<br>";
if($(this).val()=="Hello how are you")
{
$(this).closest('table').remove();
}
}
});
//alert(debug);
}
<div>
<table>
<tr>
<td colspan="2">
<div>
<table>
<tr>
<td ><span class="myclass">Hello how are you</span></td>
<td><a href="testing.php"></a></td>
</tr>
</table>
</div>
</td>
</tr>
<tr colspan="2">
<table>
<tr>
<td><b>want to remove this</b></td>
</tr>
</table>
</tr>
<tr>
<td>other content 1</td>
<td>other content 2</td>
</tr>
</table>
</div>