explode string in jquery


I'm getting the following result through ajax.


I wanna http://vinspro.org/travel/ind/ from it. I have used find and split function but it is not working . please let me know how I can get it?

var result=$(row).split('|');

chrome showing the following error

Uncaught Error: Syntax error, unrecognized expression: Shimla|1|http://vinspro.org/travel/ind/ 

This question is tagged with javascript jquery

~ Asked on 2012-12-24 19:33:17

The Best Answer is


The split method will create an array. So you need to access the third element in your case..

(arrays are 0-indexed) You need to access result[2] to get the url

var result = $(row).text().split('|');
alert( result[2] );

You do not give us enough information to know what row is, exactly.. So depending on how you acquire the variable row you might need to do one of the following.

  • if row is a string then row.split('|');
  • if it is a DOM element then $(row).text().split('|');
  • if it is an input element then $(row).val().split('|');

~ Answered on 2012-12-24 19:35:47


Split creates an array . You can access the individual values by using a index.

var result=$(row).val().split('|')[2]


var result=$(row).val().split('|');

If it's input element then you need to use $(row).val() to get the value..

Otherwise you would need to use $(row).text() or $(row).html()

~ Answered on 2012-12-24 19:34:26

Most Viewed Questions: