Yes it is, but the fact is like, two unknown persons have the name Tom and Tomy, but they are neither cousins, nor friends or relatives and they didn't know each other. That's only we can say about these two languages Java and. Java script.
var text = "Hello world";
x.innerHTML = text; // Change the content
<h1>Changing the text</h1>
Code Explanation - Normally we write the java script under head tag, but in certain instances we write it in body tag also, but it should be recommended to write java scripts in between head tags except certain conditions. In our above java script we create a function called write(),
write function in java script do as follows
Storing the text "Hello world" in a variable text.
Selecting the layer #mylayer using x=document.getElementById("mylayer");
Putting value inside the layer using x.innerHTML = text;
We already defined the value of text in var text.
Calling the function when the button is clicked, onclick="change()"
You can copy the above code in a html file and running that html file in your browser will output the result.
The above code displays a popup message Hello Friend when we click the button "Display Hello World" . I put the coding of alert in a function (look popupmsg() ) and called that function in button "onclick",
Here in the section of "onclick" users can change the event to some other like onDblClick, onMouseOver etc instead of onclick. Then the popup message "Hello World" will display only when we double click the button or moving mouse over the button.
Another method is simply calling alert in the event instead of calling it in function. That is as follows.