Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:09:27+00:00 2026-05-31T00:09:27+00:00

I am trying to grab the href tag on the element clicked in the

  • 0

I am trying to grab the href tag on the element clicked in the “navigation” div
The current code returns “#BiblesandCommentaries” every time no matter what element I click in the navigation div.

html

<div class="navigation">
        <ul>
          <li><a href="#BiblesandCommentaries">الانجيل-تعليقات</a> </li>
          <li><a href="#EnquirersLibrary">الاستفسارات</a> </li>
          <li><a href="#NewBelievers">مؤمنون جدد</a> </li>
          <li><a href="#ChristianLiving">حياة المسيحى</a> </li>
          <li><a href="#FamilyLibrary">مكتبة الأسرة</a> </li>
          <li><a href="#YoungAdultLibrary">مكتبة الشباب</a> </li>
          <li><a href="#WorshipLibrary">مزامير وتراتيل</a> </li>
          <li><a href="#BibleTeachings">التدريس</a> </li>
          <li><a href="#Leadership">القيادة</a> </li>
          <li><a href="#SchoolofChrist">مدرسة الإنجيل</a> </li>
          <li><a href="#Dota">شاگرد سازی بصورت شنیدن</a></li>
          <li><a href="#MinorityLanguages">فهم المسيح</a> </li>
        </ul>
    </div>

js

$('.navigation').click(function() {
    test = $(this).find('a').attr('href');
    alert (test);
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:09:29+00:00Added an answer on May 31, 2026 at 12:09 am

    using .find().attr() like that will always get the first one, you need to change the selector for your click function to target the a like this:

    $('.navigation a').click(function(e) {
        e.preventDefault(); //use this if you don't want to reload the page
        var test = $(this).attr('href');
        alert (test);
    }); 
    

    also you should declare your variables.

    EDIT ok commenters, I was just fixing his code, but here ya go:

    $('.navigation a').on("click",function(){
           alert($(this).attr('href'));
    });
    

    EDIT haha commenters, let’s get pedantic:

    $("div.navigation").on("click", "a", function(e) {
        e.preventDefault();
        alert ($(this).attr('href'));
    });​​​​
    

    without preventing the default operation of the a tag, you’ll be reloading the page

    EDIT: Want to take it a step further? Forget jQuery. Here’s some vanilla JS

    document.querySelector("div.navigation").onclick = function(e){
        if(e.target.href){
            e.preventDefault();
            alert(e.target.href);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to grab a div's ID in the code behind (C#) and set
I am trying to grab the link (or href attribute) from an anchor tag
Im trying to grab the title on the <li> when it is clicked. It
Hi I am trying to grab a div from another website using JS. I
I am trying to grab the value of my href in jquery how is
I'm trying to grab the href of one of my links and clone/copy that
I am trying to grab that 15 at the end of the href with
Im trying to grab a HTML source code from a webpage which needs user
Im trying to grab the LOC=URL from the following href http://url.comclickThrough?SRC=&amp;target=SP&amp;PN=1&amp;FP=listings&amp;T=Las+Vegas&amp;S=NV&amp;C=lawyer&amp;PGID=yp604.8084.1349604581940.36701144470449&amp;ALG=113&amp;TS=nbt&amp;OF=1&amp;ACTION=log,red&amp;CID=520623&amp;LID=2325743402&amp;TR=77&amp;bidType=FLCLIK&amp;relativePosition=3&amp;position=33&amp;PGSN=R1&amp;RS=49.157852&amp;CID=520623&amp;FL=url&amp;TL=off&amp;LOC=http://www.nvtalaw.com How can i
I'm trying to grab the id of the image that is clicked and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.