Are you first timer at Why not join us and start exchange your knowledge with everyone. Register today!

jQuery - get last part of URL

0 votes
added Mar 30 in jQuery by theoh_lee Lance Corporal (790 points)

When folder hierarchy increases like

$(function () {
     siteCode = getLastPartOfUrl('');

var getLastPartOfUrl =function($url) {
    var url = $url;
    var urlsplit = url.split("/");
    var lastpart = urlsplit[urlsplit.length-1];
        lastpart = urlsplit[urlsplit.length-2];
    return lastpart;


Please log in or register to example this solution. - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.