Hi,
Can anyone explain this query?
$(function() {
var pgurl = window.location.href.substr(window.location.href.lastIndexOf("/") +1);
$(".menu li a").each(function() {
if ($(this).attr("href") == pgurl || $(this).attr("href") == '')
$(this).addClass("active");
});
});
and why we add '1' in 3rd line (highlight with red color)?
Thanks in advance.


Karthikeyan KRank #554 · 4.4K reputationPosted Aug 19, 2015, 3:53 AM EDT
Arjunan SelvamRank #2,179 · 651 reputationPosted Aug 19, 2015, 3:59 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 19, 2015, 4:01 AM EDT
lastIndexOf() finds the last occurrence of your string in the string you're searching.So the first lastIndexOf() finds the last "/" in the href attribute of the link.+1 is needed, so that the url still contains the last "/".
Anubhav ChaudharyRank #29 · 42K reputationPosted Aug 19, 2015, 4:04 AM EDT