Hussein
Hussein

Reputation: 42818

Strip out portion of a url using jquery

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

Answers (5)

Aly
Aly

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

Aaron Hathaway
Aaron Hathaway

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

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

var str = 'http://images.google.com/images?q=tbn:9vPPg9Y5ojFMeM::www.maniacworld.com/amazing-cars.jpg';
alert(str.split('::')[1]);

Upvotes: 0

Rion Williams
Rion Williams

Reputation: 76557

If you want to use jQuery something like this should work:

  var result = [yourstring].split("::")[1];

Working Demo

Upvotes: 0

Keltex
Keltex

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

Related Questions