Javascript Do - While Statement

JavaScript Can Change HTML Content

One of many JavaScript HTML methods is getElementById(). in this given example we find an HTML element denoted by id="mycheck", and it changes the element content using innerHTML to "Welcome to ekgurukul.com"

document.getElementById("mycheck").innerHTML = "Welcome to ekgurukul.com";

TRY THIS CODE

<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="mycheck">JavaScript can change HTML content.</p>
<button type="button" onclick='document.getElementById("mycheck").innerHTML = "Hello JavaScript!"'>Click Me!</button>
</body>
</html>

JavaScript Can Change HTML Styles (CSS)

Changing the style of an HTML element, is a variant of changing an HTML attribute:

document.getElementById("mycheck").style.fontSize = "20px";

TRY THIS CODE

<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="mycheck">JavaScript can change the style of an HTML element.</p>
<button type="button" onclick="document.getElementById('mycheck').style.fontSize='20px'">Click Me!</button>
</body>
</html>

JavaScript Can Show HTML Elements

Showing hidden HTML elements can also be done by changing the display style:

document.getElementById("demo").style.display = "block";

TRY THIS CODE

<!DOCTYPE html>
<html>
<body>
<h2>What JavaScript Do in Programming?</h2>
<p>JavaScript can show hidden HTML elements while click button onclick event.</p>
<p id="mycheck" style="display:none">Hello JavaScript!</p>
<button type="button" onclick="document.getElementById('mycheck').style.display='block'">Click Me!</button>
</body>
</html>

Advantages Of NCERT, CBSE & State Boards Solutions For All Subjects

  • All the NCERT Solutions have been prepared by academic experts having 10+ years of teaching experience.
  • They have prepared all the solutions in simple and easy language, so that each and every student can understand the concepts easily.
  • All the solutions have been explained step to step wise in details with better explainations.
  • Students can also use these question and answers for your assignments and in homework help.
  • All the solutions have been explained in detail and the answers have been compiled in a step-wise manner.
  • All the question and asnwers are commonly prepared according to the Latest Syllabus of Board Education and Guidelines.
  • Students can know about the various types of questions asked in the exams with the help of these solutions.

Top Engineering Courses