JavaScriptで新しいHTMLタグを削除して追加しますか?
新しいHTMLタグを削除および追加するには、hide()およびshow()の概念を使用します。
以下が私たちのボタンだとしましょう-
<button type="submit" id="hide">Click Me To hide above content </button> <button type="submit" id="show">Click Me To show above content </button>
ボタンクリックでタグを削除および追加するには、hie()およびshow()-
を使用します$(document).ready(function(){
$("#hide").click(function(){
$("h1").hide();
});
$("#show").click(function(){
$("h1").show();
});
}); 例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<h1>Test JavaScript</h1>
<button type="submit" id="hide">Click Me To hide above content
</button>
<button type="submit" id="show">Click Me To show above content
</button>
<script>
$(document).ready(function(){
$("#hide").click(function(){
$("h1").hide();
});
$("#show").click(function(){
$("h1").show();
});
});
</script>
</body>
</html> 上記のプログラムを実行するには、ファイル名「anyName.html(index.html)」を保存して、ファイルを右クリックします。 VSCodeEditorで[OpenwithLiveServer]オプションを選択します。
出力
これにより、次の出力が生成されます-
ケース1
「クリックしてコンテンツの上を非表示にする」ボタンをクリックすると、次の出力が表示されます。
ケース2
「クリックして上記のコンテンツを表示するには」ボタンをクリックすると、次の出力が表示されます。
-
JavaScriptでIDで要素を削除しますか?
IDで要素を削除するには、remove()を使用できます。 例 以下はコードです- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>D
-
trタグからidを取得し、JavaScriptを使用して新しいtdに表示するにはどうすればよいですか?
以下が私たちのテーブルだとしましょう- <table> <tr id='StudentDetails'> <th>StudentName</th> <th>StudentCountryName</th> </tr> <tr id='FirstRow'> <td&