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); 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);
Comments
Post a Comment