explode string in jquery

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

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

OR

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

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()


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('|');