Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery removing part of string after "#" and removing "# "too

I wonder how can i remove all string part after "#". For example if i have example.com/hello#item1 how can i remove all characteres after # and # character too?

like image 904
krzyhub Avatar asked Aug 09 '11 18:08

krzyhub


2 Answers

var string = "example.com/hello#item1".split('#')[0];

simple as that

like image 185
Senad Meškin Avatar answered Oct 24 '22 10:10

Senad Meškin


You can just use split.

var oldString ='somestring#removethis';
var newString = oldString.split('#', 1)[0];
alert(newString);

see: http://jsfiddle.net/DGFuf/1/

like image 4
CaffGeek Avatar answered Oct 24 '22 11:10

CaffGeek