fix a jquery if stament

Hello this should be an easy one.. I need to fix this..



function menuControll(url){
//alert('checking the menu- went to: '+url); out puts the right url....
$("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
if(url==$("#menuwrapper a").each().attr('href')){
$("#menuwrapper a,#menuwrapper li").addClass('menuactive');
alert('checking the menu'); not getting called...
}
}

smaple menu is attacted

I do get the first alert and I am getting the right url.. but.. I can't seem to get the if stament..

Thank you -j
<!-- the html for the menu -->


<div  class="corner30pxRight" id="menuwrapper">
<ul id="primary-nav">
	<li class=""><a  accesskey="1" href="http://domain.com/" class="first" ><span>Home</span></a></li>
	<li class="menuparent"><a  href="http://domain.com/outfitter-guide-service.html" class="menuparent"><span>Outfitter / Guide Service</span></a>
        <ul>
            <li><a href="http://domain.com/outfitter-guide-service/what-to-bring.html" class=""><span>What to Bring</span></a></li>
            <li class="menuparent"><a href="http://domain.com/outfitter-guide-service/locations.html" class="menuparent"><span>Locations</span></a>
                <ul>
                    <li><a href="http://domain.com/outfitter-guide-service/locations/snake-river-boat-launches.html" class=""><span>Boat Launches</span></a></li>
                </ul>
            </li>
            <li><a href="http://domain.com/outfitter-guide-service/the-lodge.html" class=""><span>Lodging</span></a></li>
            <li><a href="http://domain.com/outfitter-guide-service/rates.html" class=""><span>Rates</span></a></li>
            <li><a href="http://domain.com/outfitter-guide-service/our-boats.html" class=""><span>Our Boats</span></a></li>
            <li><a href="http://domain.com/outfitter-guide-service/our-guides.html" class=""><span>Our Guides</span></a></li>
            <li><a href="http://domain.com/outfitter-guide-service/testimonials.html" class=""><span>Testimonials</span></a></li>
        </ul>
	</li>
	<li><a href="http://domain.com/contact.html" class=""><span>Contact Us</span></a></li>
	<li class="menuparent"><a href="http://domain.com/albums.html" class="menuparent"><span>Albums / Videos</span></a>
        <ul>
            <li><a href="http://domain.com/albums/Groups.html" class=""><span>Groups</span></a></li>
            <li><a href="http://domain.com/albums/boat-pictures.html" class=""><span>Boat Pictures</span></a></li>
            <li><a href="http://domain.com/albums/chukar-hunts---cast-blast.html" class=""><span>Chukar Hunts - Cast &amp; Blast</span></a></li>
            <li><a href="http://domain.com/albums/bass.html" class=""><span>Bass</span></a></li>
            <li><a href="http://domain.com/albums/fall-chinook.html" class=""><span>Fall Chinook</span></a></li>
            <li><a  href="http://domain.com/albums/spring-chinook.html" class=""><span>Spring Chinook</span></a></li>
            <li><a href="http://domain.com/albums/steelhead.html" class=""><span>Steelhead</span></a></li>
            <li><a href="http://domain.com/albums/sturgeon.html" class=""><span>Sturgeon</span></a></li>
            <li><a href="http://domain.com/albums/walleye.html" class=""><span>Walleye</span></a></li>
            <li><a href="http://domain.com/albums/wildlife.html" class=""><span>Wildlife</span></a></li>
            <li><a href="http://domain.com/albums/videos.html" class=""><span>Videos</span></a></li>
        </ul>
	</li>
	<li class="menuparent"><a  href="http://domain.com/Blogs.html" class="menuparent last" ><span>Fishing Reports</span></a>
        <ul>
            <li><a href="http://domain.com/Blogs/fish-counts-and-cam.html" class=""><span>Fish Counts and Cam</span></a></li>
        </ul>
    </li>
</ul>
<div class="clearb"></div>
</div>

Open in new window

LVL 4
jeremyBass26Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimmym715Commented:
The problem is actually that you were mis-using the .each() functionality

The code below should do the trick for you.
function menuControll(url)
    {
        $("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
        $("#menuwrapper a").each(function(i){
            if(url == $(this).attr('href'))
            {
                $("#menuwrapper a,#menuwrapper li").addClass('menuactive');
            }
        });
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeremyBass26Author Commented:
yeah I saw that... I was just trying out the code below.. but you just jogged my head.. your right I needed the if on the inner func of the each() .. tk .. -J
function menuControll(url){
    //alert('checking the menu- went to: '+url); out puts the right url.... 
    $("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
    if(url==$("#menuwrapper a").each(function(){$(this).attr('href');})){
        $("#menuwrapper a,#menuwrapper li").addClass('menuactive');
        alert('checking the menu'); 
    }
}

Open in new window

0
jeremyBass26Author Commented:
tk for the brain jog lol.. cheers
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jeremyBass26Author Commented:
wait.. shoot.. that was not right.. it's applying to all of them..


function menuControll(url)
    {
        $("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
        $("#menuwrapper a").each(function(i){
            if(url == $(this).attr('href'))
            {
                $("#menuwrapper a,#menuwrapper li").addClass('menuactive');
            }
        });
    }


$("#menuwrapper a,#menuwrapper li") get it.. hmm...
0
jeremyBass26Author Commented:
ok.. it's
function menuControll(url)
    {
        $("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
        $("#menuwrapper a").each(function(i){
            if(url == $(this).attr('href')){
                $(this).addClass('menuactive').closest('li').addClass('menuactive');
            }
        });
    }

Open in new window

0
jimmym715Commented:
ah yes...I didn't have the CSS to catch what you noticed, but you're right

try this:

function menuControll(url)
    {
        $("#menuwrapper a,#menuwrapper li").removeClass('menuactive');
        $("#menuwrapper a").each(function(i){
            if(url == $(this).attr('href'))
            {
                $(this).addClass('menuactive');
            }
        });
    }

once you're in the if statement, you've already got a handle on the element you want, so $(this) should be all you need!

0
jeremyBass26Author Commented:
umm.. no no.. sorry .. I know for sure you can use just this as this is in reference to the a only due to the href arg... so if anyone is interested...

this is what it's for... http://www.hellscanyonsportfishing.com/

here is the code as of yet..
    function menuControll(url){
        $("#menuwrapper a").each(function(i){
            if(url == $(this).attr('href')){
                $("#menuwrapper a,#menuwrapper li").removeClass('menuactive childactive');
                $(this).addClass('menuactive')
                    .closest('li').addClass('menuactive')
                    .closest('li.menuparent').addClass('menuactive childactive')
                    .closest('a.menuparent').addClass('menuactive childactive');
            }
        });
    }



this takes care of two deep but I need to go 3 deep as I just realized :/  


in case i have a related question to this site in case anyone wants to give the back button issues a wack at fixing..

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_25974975.html

tk-J
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.