แอตทริบิวต์ HTML ที่ซ่อนอยู่ใช้เพื่อสื่อสารกับผู้ใช้ว่าองค์ประกอบที่มีแอตทริบิวต์ที่ซ่อนอยู่ไม่เกี่ยวข้องกับเอกสารอีกต่อไปและผู้ใช้ไม่ควรมองเห็นได้
เรามาดูตัวอย่าง ซ่อน แอตทริบิวต์ −
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<title>HTML hidden attribute</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-hidden-attribute</legend>
<input type="text" id="textSelect" placeholder="Your Authorization Level">
<select id="selection1" hidden>
<option>Add user</option>
<option>Delete user</option>
<option>Modify user</option>
</select>
<select id="selection2" hidden>
<option>Mail admin</option>
<option>Call admin</option>
</select>
<input type="button" value="go" onclick="displaySelection()">
<div id="divDisplay">Hello</div>
</fieldset>
</form>
<script>
var textSelect = document.getElementById("textSelect");
var divDisplay = document.getElementById("divDisplay");
var selection1 = document.getElementById("selection1");
var selection2 = document.getElementById("selection2");
function displaySelection() {
if(textSelect.value === 'admin'){
selection1.hidden = false;
selection2.hidden = true;
divDisplay.textContent = 'Welcome Admin';
} else if(textSelect.value === 'user'){
selection2.hidden = false;
selection1.hidden = true;
divDisplay.textContent = 'Welcome User';
} else{
selection2.hidden = true;
selection1.hidden = true;
divDisplay.textContent = 'Your input does not match any authorization';
}
}
</script>
</body>
</html> 1) คลิก 'ไป' ปุ่มที่มีระดับการอนุญาตผู้ใช้ -

2) คลิก ‘ไป’ ปุ่มที่มีระดับการอนุญาตของผู้ดูแลระบบ -

3) คลิก 'ไป ’ ปุ่มระดับที่ไม่ได้รับอนุญาต -
