Java Script


JavaScript Tutorial


Admission Enquiry Form


innerHTML & innerText in Javascript

 

The innerHTML property sets or returns the HTML content (inner HTML) of an element.

The innerText property sets or returns the text content of the specified element.

Example of innerHTML property in JavaScript


<html>
<head>
<title>Inner Html in Javascript</title>
<script>
function change_text()
{
document.getElementById("heading").innerHTML="<font color='red'> This is the changed text</font>";
}
</script>
</head>

<body>
<h1 id="heading">This is innerHtml Property</h1>
<input type="button" value=" click " onClick="change_text()"
style="font-size:24px;">
</body>
</html>






Example of innerText property in JavaScript


<html>
<head>
<title>InnerText in Javascript</title>
<script>
function change_text()
{
document.getElementById("heading").innerText="<font color='red'> This is the changed text</font>";
}
</script>
</head>

<body>
<h1 id="heading">This is innerText Property</h1>
<input type="button" value="click" onClick="change_text()"
style="font-size:24px;">
</body>
</html>






Example of innerHTML & innerText


<html>
<head>
<title>InnerHTML concatenating old text with new text in Javascript</title>
<script>
function change_text()
{
var x=document.getElementById("mypara").innerText;

document.getElementById("mypara").innerHTML=x+"<b>COMPUHELP is also providing the data structures training for the B.Tech. Students or to the students of all computer streams to understand the deep concepts to understand the concepts and techniques which are used to manage data in computers. Data Structures is the most important for the students to get job or to crack the interview of MNCs during their recruitment times.</b>";
}
</script>
</head>

<body>
<p id="mypara">COMPUHELP is now providing online training for C, C++, JAVA, HTML,CSS,JAVASCRIPT, WEB Designing, WEB Development, Python, Data Structures, SQL, DBMS, PHP, Digital Marketing ,Computer Basics and Spoken English etc in sector 46C & sector 22C Chandigarh. COMPUHELP's Training for B.Tech. computer science students from the basic programming languages like Logic building in C Language, OOP Concepts using C++,OOP Concepts using JAVA,python for the latest technologies like machine learning and robotics etc.</p>
<input type="button" value="click" onClick="change_text()"
style="font-size:24px;">
</body>
</html>