Answer the question
In order to leave comments, you need to log in
Question for understanding Javascrpipt - why the event $('#id').click(function(){...}); works twice?
Here's the code. First, we run the function when the window is loaded, then when the window is resized.
<html><head>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script>
$( window ).on( "load", function() {
ff();
});
$(window).resize(function() {
clearTimeout(this.id);
this.id = setTimeout(ff, 1500);
});
function ff() {
var windowWidth = window.innerWidth ? window.innerWidth : $(window).width();
if( windowWidth <= 500 ) $( "#idx" ).click(function() { alert(windowWidth); });
if( windowWidth > 500 ) $( "#idx" ).click(function() { alert(windowWidth); });
}
</script>
</head><body><img src="https://assets.servedby-buysellads.com/p/manage/asset/id/32054" id="idx">
</body></html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question