Search code examples
javascriptjqueryreplacestrip

Remove part of filename with jQuery


I want to strip a filename like this: IMG_6903.JPG&width=504

to:

IMG_6903.JPG

...

My script looks like this:

  $(function(){
    $('#exposure img').each(function(){
        var $imgSrc = this.src.split('&');
        $(this).wrap('<a rel="lightBox" />')
               .parent().attr("href", ""+$imgSrc);
      });
  });    

But it doesn't work... How do I do this?


Solution

  • var imgSrc = this.src.substring(0,this.src.indexOf('&'));