Amila Amila -4 years ago 103
HTML Question

Change Title of a HTML button

I want to Change the title of a HTML button once clicked. this is what I tried.


<button class="fullScreen" data-dojo-type="dijit.form.Button" onclick="FullScreenToggle(this);" id="butFullScreen">
<input type="image" class="ns" onclick="FullScreenToggle(this);" title="Full Screen" value="" />


if (document.getElementById("butFullScreen").title == "Full Screen") {
document.getElementById("butFullScreen").title = "";
document.getElementById("butFullScreen").title = "Normal Screen";
} else document.getElementById("butFullScreen").title = "Full Screen";

When I do this Title doesn't change in JavaScript call. then I tried using
in HTML, then title changes on Java Script call. but when button is loaded first time I dont have a title. I want have Full Screen as title when button is loaded and then toggle it between Normal Screen & Full Screen on each click.

Suggestions are welcome, Thanks in Advance.


problem in brief is once I set title="Full Screen" in my HTML, java-script call doesn't change it. I there any solution or reasoning for that?


kept the title="" as blank, and called the java script method in
<body onload
method. Problem solved.

Answer Source

u need to call a function onload site Execute a JavaScript when a page is finished loading:


<body onload="FullScreenToggle();">

In JavaScript:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download