-3

Example url:

www.example.com/example/createnew/#47

or

www.example.com/example/createnew/#5462

I want to put the number behind the '#' in a variable. but the size of the number can change.

how do i do this?

(without jquery or any other library)

wormen22
  • 1
  • 3

3 Answers3

1

You can use split()

var res = 'www.example.com/example/createnew/#5462'.split('#')[1],
  res1 = 'www.example.com/example/createnew/#47'.split('#')[1];
document.write(res + '<br>' + res1);
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0
var url = 'www.example.com/example/createnew/#5462';
var num = parseInt(url.match(/\d+$/)[0]);
Matt Harrison
  • 13,381
  • 6
  • 48
  • 66
0

try this:

var val = "www.example.com/example/createnew/#422";
var myString = val.substr(val.indexOf("#") + 1)
alert(myString);
FalcoB
  • 1,333
  • 10
  • 25