Set variable after function jquery
<p>I want to declare a function, but only run it later on after setting the variables below.</p>

<p>Essentially I am checking the URL and seeing if it matches anything in the menu and then setting that item as selected. I know there are better ways to probably do this, but now I'm determined to find out how to make this work. I have written a function that works on a single item, but I want to run it on both.</p>

<p>Hopefully this makes sense:</p>

<pre><code>var itemOne = $("#side-bar li a");
var itemTwo = $("#navigation ul li a");

$(function() {

function doosomething() {     

    var url = document.location.href;    
    // URL of Page

    $(someVar).each(function(){         
        var href = $(this).attr('href');
        // URL of Link

        if (url.indexOf(href) &gt; -1) {

            $(this).parent().addClass('selected'); 
            console.log('yes');

        }
        else {
            console.log('no');
        }

    });

    } 

    someVar = itemOne,itemTwo        

    doosomething();    

});  
</code></pre>

<p>Thanks in advance!</p>

<p>I want to combine this into one.</p>

<pre><code>someVar = itemTwo; 
doosomething();

someVar =itemOne;
doosomething();
</code></pre>

<p>Currently I'm just running it like this:</p>

<pre><code>var url = document.location.href;    
console.log(url);

$("#side-bar li a").not('li.home-item a').each(function(){          
    var href = $(this).attr('href');
    console.log(href);

    if (url.indexOf(href) &gt; -1) {

        $(this).parent().addClass('selected'); 
    }
    else {
        console.log('no');
    }

});
</code></pre>
