Reputation: 42818
Google produces image thumbs like so http://images.google.com/images?q=tbn:9vPPg9Y5ojFMeM::www.maniacworld.com/amazing-cars.jpg
I only need the main image url which in this case is www.maniacworld.com/amazing-cars.jpg I noticed we have :: before the main image url
What is the easiest way to do this via jquery.
Upvotes: 3
Views: 1220
Reputation: 16255
you dont need jquery you can simply use string split with javascript, but if you want jquery here you go:
$('urlSelector').attr('href').split('::')[1]
Upvotes: 0
Reputation: 4315
I'd do it with JavaScript's split()
method if you're sure "::" will always proceed what you're after.
var parts = url.split("::");
var image_url = parts[1];
Upvotes: 0
Reputation: 1038830
var str = 'http://images.google.com/images?q=tbn:9vPPg9Y5ojFMeM::www.maniacworld.com/amazing-cars.jpg';
alert(str.split('::')[1]);
Upvotes: 0
Reputation: 76557
If you want to use jQuery something like this should work:
var result = [yourstring].split("::")[1];
Upvotes: 0
Reputation: 26426
You don't need jquery, you can probably just use a regular expression.
var re= /.+::/
var newurl = googleurl.replace(re,'');
Here's a working demo: http://jsfiddle.net/Rsefq/
Upvotes: 1