0

I have footer links on my website and I'm trying to get the title attributes of the anchor tag using the following method.

(function($){
    $("#block-footermenu a.nav-link").each(function(e) {
        console.log($(e).attr('title'));
    });
})(jQuery);

but in the console, I'm getting undefined what I'm missing here?

Following is my HTML

<nav role="navigation" aria-labelledby="block-footermenu-menu" id="block-footermenu" class="block block-menu navigation menu--footer-menu">
    <ul class="nav ul_align">
        <li class="nav-item">
            <a class="nav-link" title="Sitemap" href="/us/sitemap">Sitemap</a>
        </li>
    </ul>
</nav>

1 Answer 1

1

You should use $(this) to refer back to the element on which you have clicked.

(function($){
    $("#block-footermenu a.nav-link").each(function(e) {        
        console.log($(this).attr('title'));
    });
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav role="navigation" aria-labelledby="block-footermenu-menu" id="block-footermenu" class="block block-menu navigation menu--footer-menu">
    <ul class="nav ul_align">
        <li class="nav-item">
            <a class="nav-link" title="Sitemap" href="/us/sitemap">Sitemap</a>
        </li>
    </ul>
</nav>

Sign up to request clarification or add additional context in comments.

Comments

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.