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:
var first = $(location).attr('pathname');
first.indexOf(1);
first.replace('/', '');
first.toLowerCase();
alert(first);
but it’s not working as intended. Can anyone help? Thanks
Advertisement
Answer
var first = $(location).attr('pathname');
first.indexOf(1);
first.toLowerCase();
first = first.split("/")[1];
alert(first);