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 7896249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:50:45+00:00 2026-06-03T07:50:45+00:00

I have a few Collapsible segments in my Code which i have implemented using

  • 0

I have a few Collapsible segments in my Code which i have implemented using jQuery.

Like this:

<h2 class="expand">Link1</h2>
                <div class="collapse">
                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore 
                    et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
                    ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore 
                    eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa 
                    qui officia deserunt mollit anim id est laborum.</p>                
                    <p class="top"><a href="#content">Top of page</a></p>
                </div>

There are a few more identical sections like the code above.

I want to get the ID of each of these headings when i click it . Say, when i click “Link1”, i want its ID to Pop-up.

I have already defined the function for displaying the id in a pop-up. Here it is :

 $(document).ready(function () {
        $("a").click(function (event) {
          alert(event.target.id);
        });
  });

Whenever i run the application and click on (say) “Link1”, I get a blank output. Declaring seperate classes for all the links seems to be an option but i want to do it otherwise..
Can anyone suggest any alternative as to how to get the Id’s of these elements??

  • 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-06-03T07:50:46+00:00Added an answer on June 3, 2026 at 7:50 am

    Your supplied markup suggests that you haven’t given an id to these elements. Try giving them an ID, like so:

    <a id="contentLink" href="#content">Top of page</a>
    

    Then you can do:

     $(document).ready(function () {
        $("a").click(function (event) {
            alert($(this).attr("id"));
        });
     });
    

    Edit: or if when you say “ID”, you actually mean href (as your markup has href attributes), then you can do:

    $(document).ready(function () {
        $("a").click(function (event) {
            alert($(this).attr("href"));
        });
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few buttons of which each button is assigned a class with a
i have few variables like this: self.lamp_1 self.lamp_2 self.lamp_3 self.lamp_4 and now i want
I have few textviews and it looks like this now: ramdomName 10.20 - 11.30
I have few different applications among which I'd like to share a C# enum.
i have few texboxt and dropdownlist, which their id would be something like txtName1,
I have few questions about this code: <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv =
I have few lines of C++ code which has simple purpose - to store
i have few div's in my form which needs to be hidden at first
I have few jquery tabs for my docs e.g. <div id=doc-tabs> <ul id=doc-list> <li><a
I have few textblocks, with custom font family which work fine: FontFamily={StaticResource CodeBold} This

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.