Guest User

Untitled

a guest
Jul 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. $('a[href$=".png"]').click(function() {
  2. // do something smart
  3. });
  4.  
  5. $('a[href$=.jpg],a[href$=.jpeg],a[href$=.png]').click(function() {
  6. // do something even smarter
  7. });
  8.  
  9. $('a').click(function(){
  10. var href = this.href;
  11. var hrefParts = href.split('.'); //array(0: fileName, ...length - 1: extension)
  12. if(hrefParts[hrefParts.length - 1] == 'png'){...}
  13. //etcetera...
  14. });
  15.  
  16. $('a').each(function() {
  17. var ext = $(this).attr('href').substr('-4');
  18. if (ext == '.png' || ext == '.jpg') {
  19. ... continue ...
  20. }
  21. });
  22.  
  23. $('a').click(function(e) {
  24. var ext = $(this).attr('href').split('.').slice(-1);
  25. switch( ext ) {
  26. case 'png':
  27. // Code for PNGs!
  28. break;
  29. case 'jpg':
  30. case 'jpeg':
  31. // Code for JPGs!
  32. break;
  33. default:
  34. // Otherwise....
  35. }
  36. });
  37.  
  38. var extToFun = {
  39. png:function(){},
  40. gif:function(){}
  41. };
  42.  
  43. $('a').click(function(){
  44. var href = this.href.split('.');
  45. var ext = href[hrefParts.length - 1];
  46. if(extToFun[ext])extToFun[ext].call(this);
  47. });
Add Comment
Please, Sign In to add comment