jquery - Highlight menu by querystring ignore case sensitive -
i use jquery highlight menu. , here html like
<div id="menu"> <div class="item"><a href="?product=abc">abc</a></div> <div class="item"><a href="?product=xyz">xyz</a></div> <div class="item"><a href="?product=test">test</a></div> </div>
assumed got value of current querystring: urlparams["product"] (by using andy e's code in here)
$(document).ready(function() { $("#menu").find("a[href='?product=" + urlparams["product"] + "']").addclass("selected"); });
it work if querystring href. how can make non-case sensitive? thank much
you can use .tolowercase()
method:
$("#menu").find("a").filter(function(){ return this.href.tolowercase().indexof(urlparams["product"].tolowercase()) > -1; }).addclass("selected");
or:
var query = urlparams["product"].tolowercase(); $("#menu a").filter(function(){ return this.href.split('=')[1].tolowercase() === query; }).addclass("selected");
Comments
Post a Comment