Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 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.

Once I set title="Full Screen" in my HTML, a JavaScript call doesn't change it.

like image 791
Amila Avatar asked Nov 06 '25 22:11

Amila


1 Answers

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();};
like image 149
Michał Szałapski Avatar answered Nov 08 '25 15:11

Michał Szałapski