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"); 

http://jsfiddle.net/ruykn/


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -