Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Javascript: indicate when item in a list clicked?

Javascript: indicate when item in a list clicked?

Scheduled Pinned Locked Moved JavaScript
javascripthtmlcomquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xarzu
    wrote on last edited by
    #1

    function registerHandlers() {
    var as = document.getElementsByTagName('a');
    for (var i = 0; i < as.length; i++) {
    as[i].onclick = function() {
    alert(i);
    return true;
    }
    }
    }

    And HTML:

    In my life, I used the following web search engines:
    Yahoo!
    AltaVista
    Google

    L M 2 Replies Last reply
    0
    • X Xarzu

      function registerHandlers() {
      var as = document.getElementsByTagName('a');
      for (var i = 0; i < as.length; i++) {
      as[i].onclick = function() {
      alert(i);
      return true;
      }
      }
      }

      And HTML:

      In my life, I used the following web search engines:
      Yahoo!
      AltaVista
      Google

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Do you have a question?

      1 Reply Last reply
      0
      • X Xarzu

        function registerHandlers() {
        var as = document.getElementsByTagName('a');
        for (var i = 0; i < as.length; i++) {
        as[i].onclick = function() {
        alert(i);
        return true;
        }
        }
        }

        And HTML:

        In my life, I used the following web search engines:
        Yahoo!
        AltaVista
        Google

        M Offline
        M Offline
        Member_14690874
        wrote on last edited by
        #3

        Other option for scripting with onclick functionality <pre> function registerHandlers() { var as = document.getElementsByTagName('a'); for (var i = 0; i < as.length; i++) { as[i].addEventListener('onclick', function() { alert(i); return true; }); } } //Call Function Here on window load window.addEventListener('load', function() { registerHandlers(); });</pre>

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups