1.Create a HTML FIle Using Id Attribute
<!DOCTYPE html>
<html>
<head>
<style>
#myHeader {
background-color: lightblue;
color: black;
padding: 40px;
text-align: center;
font-size: 40px;
}
h2{
color:red;
font: 30px;
}
p{
color:red;
font-size: 30px;
}
</style>
</head>
<body>
<h2>The id Attribute</h2>
<p>Use CSS to style an element with the id "myHeader":</p>
<h1 id="myHeader">Bajarangi soft</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#myHeader {
background-color: lightblue;
color: black;
padding: 40px;
text-align: center;
font-size: 40px;
}
h2{
color:red;
font: 30px;
}
p{
color:red;
font-size: 30px;
}
/* Style all elements with the class name "city" */
.city {
background-color: tomato;
color: white;
padding: 10px;
}
</style>
</head>
<body>
<h2>The id Attribute</h2>
<p>Use CSS to style an element with the id "myHeader":</p>
<h1 id="myHeader">Bajarangi soft</h1>
<!-- Multiple elements with same class -->
<h2 class="city">London</h2>
<p>London is the capital of England.</p>
<h2 class="city">Paris</h2>
<p>Paris is the capital of France.</p>
<h2 class="city">Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</body>
</html>
<!DOCTYPE html> <html> <body> <p><a href="#C4">Jump to Chapter 4</a></p> <p><a href="#C10">Jump to Chapter 10</a></p> <h2>Chapter 1</h2> <p>This chapter explains web designing</p> <h2>Chapter 2</h2> <p>This chapter explains web designing</p> <h2>Chapter 3</h2> <<p>This chapter explains web designing</p> <h2 id="C4">Chapter 4</h2> <p>This chapter explains web designing</p> <h2>Chapter 5</h2> <p>This chapter explains web designing</p> <h2>Chapter 6</h2> <p>This chapter explains web designing</p> <h2>Chapter 7</h2> <p>This chapter explains web designing</p> <h2>Chapter 8</h2> <p>This chapter explains web designing</p> <h2>Chapter 9</h2> <p>This chapter explains web designing</p> <h2 id="C10">Chapter 10</h2> <p>This chapter explains web designing</p> <h2>Chapter 11</h2> <p>This chapter explains web designing</p> <h2>Chapter 12</h2> <p>This chapter explains web designing</p> <h2>Chapter 13</h2> <p>This chapter explains web designing</p> <h2>Chapter 14</h2> <p>This chapter explains web designing</p> <h2>Chapter 15</h2> <p>This chapter explains web designing</p> <h2>Chapter 16</h2> <p>This chapter explains web designing</p> <h2>Chapter 17</h2> <p>This chapter explains web designing</p> <h2>Chapter 18</h2> <p>This chapter explains web designing</p> <h2>Chapter 19</h2> <p>This chapter explains web designing</p> <h2>Chapter 20</h2> <p>This chapter explains web designing</p>> <h2>Chapter 21</h2> <p>This chapter explains web designing</p> </body> </html>
<!DOCTYPE html>
<html>
<body>
<h2>Using The id Attribute in JavaScript</h2>
<p>JavaScript can access an element with a specified id by using the getElementById() method:</p>
<h1 id="myHeader">Hello World!</h1>
<button onclick="displayResult()">Change text</button>
<script>
function displayResult() {
document.getElementById("myHeader").innerHTML = "Have a nice day!";
}
</script>
</body>
</html>