javascript - Jquery Url Split and grab mid value -
i have url www.xyz.com/partyevent/zalen
is there way grab url mid value i.e "partyevent" , spit parts before , after that. want mid value "partyevent" adding class body.
$(document).ready(function () { var url = window.location.pathname; var count = url.match(new regexp("/", 'g')); var urlsplit = url.split("/"); var page_class = urlsplit[count.length]; alert(page_class); $('body').addclass(page_class); });
thanks help..
try this:
$(function () { var url = window.location.pathname; var urlsplit = url.split("/"); // returns array of ["","partyevent",zalen] var page_class = urlsplit[1]; // need not bother count when u need word after domain alert(page_class); $('body').addclass(page_class); });
Comments
Post a Comment