Need to hide the clicked div.
I tried with an example in jsfiddle. As i am new to js i want a better solution.
<div class="t1">1</div>
<div class="t2">2</div>
<div class="t3">3</div>
<div class="t4">4</div>
<div class="t5">5</div>
Need to hide the clicked div.
I tried with an example in jsfiddle. As i am new to js i want a better solution.
<div class="t1">1</div>
<div class="t2">2</div>
<div class="t3">3</div>
<div class="t4">4</div>
<div class="t5">5</div>
Pls find the working snippet added below
$('body').on('click','.t11',function(){
$(this).hide();
var that = $(this);
setTimeout(function() {
that.show();
}, 1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="t1 t11">1</div>
<div class="t2 t11">2</div>
<div class="t3 t11">3</div>
<div class="t4 t11">4</div>
<div class="t5 t11">5</div>
do do something like,
function hideAndShow(element, timeout){
element.style.display = "none";
setTimeout(function(){
element.style.display = "block";
},timeout);
}
hideAndShow(document.getElementById("myDiv"), 10000)
div#myDiv{
width:100px;
background-color: #f00;
height:100px;
}
<div id="myDiv">
<div>
Use setTimeout()
method for that.
// get all div and iterate over them
// for newer browser you can use Array.from
// to convert NodeList to array
[].slice.call(document.querySelectorAll('.t')).forEach(function(e) {
// attach event listener to the element
e.addEventListener('click', function() {
// hide the element
this.style.display = 'none';
// set timer
setTimeout(function() {
// show the element
this.style.display = 'block';
// bind the this context or you can use `e`
}.bind(this), 10000);
})
});
<div class="t">1</div>
<div class="t">2</div>
<div class="t">3</div>
<div class="t">4</div>
<div class="t">5</div>