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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:30:45+00:00 2026-05-19T10:30:45+00:00

i have an html page, which is consist of many hyperlink like this inside

  • 0

i have an html page, which is consist of many hyperlink like this inside body tag…

<a href="http://www.example.com/?id=313354">User Name</a>

then i decide to use unobtrusive javascript … then i’d like to change all the “a” tag to be…

<a id="354313" href=#>User Name</a>

when i click the second link above, i want that it’ll call a function like the first link does,…
my question is how to get all the “a” element inside body tag then apply a function depend it’s id…

  • 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-19T10:30:46+00:00Added an answer on May 19, 2026 at 10:30 am

    What you’re after is this code:

    <script type="text/javascript">
    window.onload = function WindowLoad() {
        var arrLinks = document.getElementsByTagName("a");
        for (var i = 0; i < arrLinks.length; i++) {
            var oLink = arrLinks[i];
            var sCurHref = oLink.href;
            if (sCurHref.indexOf("?id=") >= 0) {
                var ID = sCurHref.split("?id=")[1];
                if (ID.length > 0) {
                    oLink.id = ID;
                    oLink.href = "#";
                    oLink.onclick = function() {
                        document.location.href = sCurHref;
                        return false;
                    }
                }
            }
        }
    }
    </script>
    

    This will iterate all the links, changing the visible HREF to “#” and preserving their functionality, applying the proper ID. (Though you didn’t say what’s the use of that ID)

    Feel free to mess around with the live test case: http://jsfiddle.net/yahavbr/uMbEY/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML page which contains an href tag. On clicking href link,
My page structure is like I have a html page which consist of a
I have a html page which consist of a table & I want to
I have this html page which is very simple, it contains a text box
I'd like to have an HTML page which displays a single PNG or JPEG
I have a html-page which I would like to style (using IE9). The following
I have an HTML page which contains an Object tag to host an embedded
I have html page which has following line with some html entities like &#146;.
We have an HTML page which displays a bunch of pretty bars using divs
I have an html page which has a link called open. Once the link

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.