Amila Amila - 3 months ago 5
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.

HTML

<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="" />


JS

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
title=""
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.

Update

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?

Solved

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

Answer

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

In HTML:

<body onload="FullScreenToggle();">

In JavaScript:

window.onload=function(){FullScreenToggle();};
Comments