[jQuery]remove()で指定複数属性の要素を削除する

2021年8月11日

書式
remove([expr])
全ての要素をドキュメントから削除する。
使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$obj = $("input[name='username'][type='hidden'][value='uu01']")
if ($(obj.length > 0) {
$obj.remove();
}
$obj = $("input[name='username'][type='hidden'][value='uu01']") if ($(obj.length > 0) { $obj.remove(); }
$obj = $("input[name='username'][type='hidden'][value='uu01']")
if ($(obj.length > 0) { 
       $obj.remove();
}

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$(button).click(function(){
$("div").remove();
}
$(button).click(function(){ $("div").remove(); }
$(button).click(function(){
  $("div").remove();
}

 

jQuery

Posted by arkgame