jquery - Want to run only one if Condition -




what if screen width < 1200 alert('1200') alert shown , when screen width < 640 alert('640') alert shown. need without use of else block.

fiddle

if ($(window).width() < 1200) {    alert('1200');  }  if ($(window).width() < 640) {    alert('640');  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

use if/else if. way first matching branch followed. note logic work in case you'd need reverse order of conditions. try this:

if ($(window).width() < 640) {    alert('640');  } else if ($(window).width() < 1200) {    alert('1200');  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

as side note, detecting browser width sign you're amending ui different resolutions. if that's case can achieve same thing in much better way using css media queries.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -