Jquery version check vs. needed version


/ Published in: jQuery
Save to your folder(s)

Checks if JQuery is loaded and then checks if loaded version of JQuery >= needed version


Copy this code and paste it in your HTML
  1. function isJQueryValidVersion(version) {
  2. var validVersion = true;
  3. if (typeof jQuery != 'undefined') {
  4. if ((typeof version != 'undefined') && (version != '')) {
  5. var neededVersion = version.split('.');
  6. var jQver = jQuery.fn.jquery.split('.');
  7. for (var i = 0; i < jQver.length; i++) {
  8. var actset = parseInt(jQver[i]);
  9. if (neededVersion.length >= (i+1)) {
  10. var actneeded = parseInt(neededVersion[i]);
  11. if (actneeded > actset) {
  12. validVersion = false;
  13. break;
  14. } else if (actneeded < actset) {
  15. validVersion = true;
  16. break;
  17. } else {
  18. continue;
  19. }
  20. } else {
  21. if (actset >= 0) {
  22. validVersion = true;
  23. break;
  24. }
  25. }
  26. }
  27. }
  28. } else {
  29. validVersion = false;
  30. }
  31. return validVersion;
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.