Reputation: 5598
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?
Upvotes: 1
Views: 543
Reputation: 25475
You split the string but try using the array instead of the first element. Try this
$(function(){
$('#exposure img').each(function(){
var $imgSrc = this.src.split('&');
$(this).wrap('<a rel="lightBox" />')
.parent().attr("href", "" + $imgSrc[0]);
});
});
Hope this helps.
Upvotes: 0
Reputation: 16845
use split
var str = 'IMG_6903.JPG&width=504';
var array = str.split('&');
array[0];
array[0] will be IMG_6903.JPG
Upvotes: 0
Reputation: 5435
var andIndex = tmpString.indexOf('&');
tmpString = tmpString.substr(0, andIndex);
Upvotes: 0