0

This is my code:

            <li>
                <a href="{{ path('homepage') }}" class="active">
                    <i class="fa fa-tasks fa-fw"></i> 
                    {% trans %} global.item {% endtrans %} <span id="pending-badge" class="badge pull-right">{{ pendingItems() }}</span>
                </a>
            </li>

And I have this jQuery too:

    $('#pending-badge').click(function () {
        window.location.href = '{{ path('pending') }}';
    });

However I've noticed clicking the badge doesn't actually redirect me to that page.

If I put console.log('test'); in the jQuery function I do see it in the console so I know the event is being registered. But I think because it's occurring in that broader <a> link it's just defaulting to that (homepage) instead of the link I provide (pending) in the jQuery.

How can I fix this?

1 Answer 1

1

You can prevent the default action by return false or by calling event.preventDefault()

$('#pending-badge').click(function (e) {
    window.location = 'http://google.com';
    return false;
});
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thanks... out of interest if I returned "true", would that mean it would continue and allow the default action?

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.