Any Way To Keep An Html Button Pressed?
I have a button . Is there any way to keep it visually pressed and unpress it via javascript? Thanks
Solution 1:
I would try CSS and use the border-style inset
, personally.
<inputtype="button" value="Inset Border" style="border-style:inset;" />
For a list of different styles, please see this jsFiddle.
Solution 2:
No, that's not possible.
I'd suggest you to use something like the jQuery UI Buttons. They support exactly this behaviour: http://jqueryui.com/demos/button/#checkbox
Solution 3:
There is no way to do that with javascript.
But you can use javascript to simulate that effect by adding/removing a css class, or directly editing the css properties you have chosen to use.
Solution 4:
toggle the visual state of the button by:
btn.onclick=function(e) {
this.style.borderStyle = (this.style.borderStyle!=='inset' ? 'inset' : 'outset');
}
when you need to see if it's depressed simply check if btn.style.borderStyle==='inset'
Solution 5:
functionpp() {
if(document.getElementById('pBut').innerHTML == 'Pause'){
// do some stuffdocument.getElementById('pBut').innerHTML = 'Continue';
document.getElementById('pBut').style.borderStyle = 'inset';
}
else {
// do some other stuffdocument.getElementById('pBut').innerHTML = 'Pause';
document.getElementById('pBut').style.borderStyle = 'outset';
}
}
<buttonid="pBut"type="button"onclick="pp()"title="Pause or continue the chapter.">Pause</button>
Works for me. Tested With FireFox and Opera, but should be compatible with all browsers.
Post a Comment for "Any Way To Keep An Html Button Pressed?"