i have a button and label like this:
<button id="btn">Button</button>
<label id="lbl">lbl</label>
When i click this button second time that label want to hide/dissappear
You can use the onclick event of the button. Add JQuery and use the below code.
var cnt = 0;
$('#btn').on('click', function() {
cnt++;
if(cnt == 2)
$('#lbl').hide();
})
OR, in vanilla js you can use
var cnt = 0;
document.getElementById('btn').onclick = function() {
cnt++;
if(cnt == 2)
document.getElementById('lbl').style.display = 'none';
};
SOLUTION
Use Inbuilt JS event
There is event in JS ondblclick event which fires only on double clicked check the snippet below
function hide() {
document.querySelector("label").style.display= "none";
}
<button ondblclick="hide()" id="btn">Button</button>
<label id="lbl">Hide me after Double clicking on button</label>
Code :
button = document.getElementById("btn")
label = document.getElementById("lbl")
button.addEventListener('dblclick', function(){
label.style.display = 'none';
})
<button id="btn">Button</button>
<label id="lbl">lbl</label>