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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:33:22+00:00 2026-05-13T16:33:22+00:00

Am looking for how to click links on my page using javascript. In my

  • 0

Am looking for how to click links on my page using javascript. In my page i show each record from my database . and a ‘show’ link to the right clicking it will expand and display the row in detail. i want to expand all the rows at once . Is it possible to click link in Javascript like this?

  • 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-13T16:33:23+00:00Added an answer on May 13, 2026 at 4:33 pm

    You can cycle through all of the anchors, and click them, yes:

    var myLinks = document.getElementsByTagName("a");
    for (var i = 0; i < myLinks.length; i++) {
      myLinks[i].click();
    }
    

    Note that this will click every link on the page. You can focus more on a specific set of links by going through a parent container that sits just outside of them:

    var myLinks = document.getElementById("container").getElementsByTagName("a");
    

    This would get all links within the element having the id value of “container”.

    Update2:

    Within the comments, you wanted to know how to click only links whose ID begins with a specific string. Let’s look at a couple ways we can implement that into our aforementioned code:

    Using jQuery, you could click all id='reviews-show...' links like this:

    $("a[id^='reviews-show']").click(); // simple, eh?
    

    The ^= in this selector matches in a regular-expression style, asking if the string starts with “reviews-show,” which will retrieve only the a tags for which this statement is true.

    If you want to stick with just regular javascript, we can modifiy our first code-block to check the substring:

    var myLinks = document.getElementsByTagName("a");
    for (var i = 0; i < myLinks.length; i++) {
      currentlink = myLinks[i];
      if (currentlink.id.substring(0,12) === "reviews-show") {
        currentlink.click();
      }
    }
    

    Update:

    Apparently jQuery is rotting my mind, and my solution doesn’t work as-is. If you don’t mind using jQuery (you’d love it), you could go this route:

    $("a").click();           //clicks all links on page
    $("#container a").click();//clicks all links within element having id 'container'
    

    If you want to stay away from a framework, try adding this prototype extension into the top of your code which will make my original answer sufficient:

    HTMLElement.prototype.click = function() {
      if (document.createEvent) {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
      } else if (this.fireEvent) {
        this.fireEvent("onclick");
      }
    }
    

    Source: http://www.barattalo.it/2009/11/18/click-links-with-javascript/

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

Sidebar

Related Questions

I have a php page where I add and delete items from database using
I'm looking for the Highlight code -> right-click -> Extract Method type of functionality
I'm looking for solution to get time to click on element using implicitlyWait in
Recently I've been looking at opening a tab using this script: $('.tofour').click(function() { //
I am currently looking at changing from using css to LESS in my current
So I need to open tabs from my website to other websites using JavaScript
I'm currently redesigning my website and have been looking into using JavaScript and jQuery.
Given the example below (click content on the right if you're using the jsfiddle
Using the .NET Windows Forms WebBrowser control to show the preview of a page,
I am looking to disable the Command + Click combination on a toolbar button

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.