javascript - Remove everything after a certain character -


is there way remove after character or choose character? i'm getting value href , "?", , it's going different amount of characters.

like this

/controller/action?id=11112&value=4444 

i want href /controller/action only, want remove after "?".

i'm using now:

 $('.delete').click(function (e) {      e.preventdefault();       var id = $(this).parents('tr:first').attr('id');                      var url = $(this).attr('href');       console.log(url);  } 

var s = '/controller/action?id=11112&value=4444'; s = s.substring(0, s.indexof('?')); document.write(s); 

sample here

edit:

i should mention native string functions faster regular expressions, should used when necessary (this isn't 1 of cases).

2nd edit:

updated code account no '?':

var s = '/controller/action'; var n = s.indexof('?'); s = s.substring(0, n != -1 ? n : s.length); document.write(s); 

http://jsfiddle.net/l4hna/1/


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -