If I have a url like:
http://localhost:53830/Organisations/1216/View
I want to alert the first part of the url path in lowercase format e.g. ‘organisations’
So far I have:
JavaScript
x
10
10
1
var first = $(location).attr('pathname');
2
3
first.indexOf(1);
4
5
first.replace('/', '');
6
7
first.toLowerCase();
8
9
alert(first);
10
but it’s not working as intended. Can anyone help? Thanks
Advertisement
Answer
JavaScript
1
10
10
1
var first = $(location).attr('pathname');
2
3
first.indexOf(1);
4
5
first.toLowerCase();
6
7
first = first.split("/")[1];
8
9
alert(first);
10