以下を含むHTMLドキュメントがあるとします。
<form id = "my_form">
<input type = "text" />
<input type = "text" />
<input type = "text" />
<button type = "button" onclick = "removeGoodInputs()">Do the job</button>
</form>
ある条件を満たす入力値を削除したい(JSで指定)。関数を作成しようとしましたがremoveGoodInputs()
(以下のように)、これによりフォームからすべての入力が削除されます。この問題を解決するにはどうすればよいですか?
function removeGoodInputs() {
$("#my_form input").each(function() {
if(this.attr("value") == 10)
$(this).remove();
});
}