I think that I am on the right track but I need your help.
I use this code to get my URL parameter
function $urlParam(name){
if(window.location.href.indexOf(name) != -1) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
return 0;
}
$(function() {
var $page='#'+$urlParam('id');
});
And than I tried to filter that data with
$side_menu.find('> li > a').filter($page).click();
But this doesn’t work.
Is there anything that I can do so I can filter data with $page variable?
If you need any more data I would be glad to provide it to you.
Thank you in advance,
Prokka
Ok, first off, instead of:
you might as well use:
as that is just the parameter part of the URL (the part you want). Also, your variable:
… the “$foo” variable naming convention is usually meant to be applied to jQuery object variables. In other words:
So (unless you have your own, different convention) I think “$page” should really be named page .
As for:
$side_menu.find('> li > a').filter($page).click();I can’t tell for sure, but it looks like you’re filtering on an id. Is that correct? If so, filter makes no sense; IDs are by definition unique on the page, so simply doing:
is totally the same thing (even performance-wise).
Without knowing the value of your page variable it’s hard to say. I’d suggest adding this:
console.log($page); $side_menu.find('> li > a').filter($page).click();Well, if you’re using Firebug or a browser with a console (if not … you should be using Firebug 😉 but you could also just change it to “alert($page)”).
When you do that, you should see what selector you’re really using. Most likely something is wrong with it. If you don’t see anything obvious, try adding:
console.log($page); console.log($($page)); $side_menu.find('> li > a').filter($page).click();(the alert trick won’t work for this one). This should show you what elements (if any) jQuery selected using your selector. Between this and reviewing the selector itself, you’ll likely find the problem (and if you don’t, maybe try playing around with running the commands in the Firebug console manually)