1

I have this code to slide some messages,

JavaScript

$(function() {
    $('#bottom_menu li a').click(function(e) {
        e.preventDefault();
        animateSlider(this.hash);
    });

    function animateSlider(hash) {
        if (!$('#container div.open').length) {
            if (hash == '#about') {
                openPopup(hash);
            }
            if (hash == '#contact') {
                openPopup(hash);
            }
        } else {
            if (hash == '#about') {
                openAndClose(hash)
            }
            if (hash == '#contact') {
                openAndClose(hash)
            }
        }
    }

    function openPopup(hash) {
        $(hash + '_popup').slideToggle().addClass('open');
    }

    function openAndClose(hash) {
        if ($(hash + '_popup').hasClass('open')) {
            $($(hash + '_popup')).slideToggle().removeClass();
        } else {
            $('#container div.open').slideToggle().removeClass();
            $(hash + '_popup').slideToggle().addClass('open');
        }
    }
});

HTML

<nav id="men55">
    <ul id="bottom_menu">
        <li style="text-align:left;">
            <a href="#about"><font face="din" size="4">onde <br />estamos</font></a>
        </li>
        <li style="text-align:left;">
            <a href="#contact"><font face="din" size="4">osnossos<br />parceiros</font></a>
        </li>
        <li style="text-align:left;">
            <a href="index2.php?web=news" <?php if($web == "news") {echo 'class="corrente"';} ?>><font face="din" size="4">news <br />press</font></a>
        </li>
    </ul>
</nav>

The problem is, when href=#contact or href=#about works fine, but if i want put a href=index2.php?web=teste don´t work... nothing happens... the problem is the javascript block the click inside nav or li

1
  • 2
    because you checking the hash - this.hash. Commented Oct 11, 2013 at 10:57

1 Answer 1

2

Simply change your initial selector to only select anchor tags whose href property starts with "#" using [href^="#"]. Change:

$('#bottom_menu li a').click(function(e) { ... });

To:

$('#bottom_menu li a[href^="#"]').click(function(e) { ... });

This will ignore any links whose href property doesn't start with "#":

#about /* Prevented */
#contact /* Prevented */
index2.php /* Ignored */
index2.php?web=teste /* Ignored */
index2.php#test /* Ignored */
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but sorry i can´t change the code like you said... can you please change my original code and send me? thanks once again
@Ricardo on the second line of the code you've posted in your question is $('#bottom_menu li a'). Simply change that to $('#bottom_menu li a[href^="#"]'). I've edited my answer for more clarity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.