Injecting String within a String in Javascript (substring)

Hi Kids,

This is how to insert String within a String using Javascript’s Substring.

    $(".footer-icons > .icon-item > a").mouseover(function(e){          
          var currentSrc = $(this).find("img").attr("src");
          var newSrc = currentSrc.substring(0,currentSrc.lastIndexOf('.'));
          newSrc += "-green.jpg";
          $(this).find("img").attr("src",newSrc);            
    });
    $(".footer-icons > .icon-item > a").mouseout(function(e){          
          var currentSrc = $(this).find("img").attr("src");
          var newSrc = currentSrc.substring(0,currentSrc.lastIndexOf('.')-6);
          newSrc += ".jpg";
          $(this).find("img").attr("src",newSrc);            
    });

Drop a comment for your questions Kids.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *