Web Analytics Made Easy -
StatCounter Javascript Affect a Certain Section - CodingForum

Announcement

Collapse
No announcement yet.

Javascript Affect a Certain Section

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript Affect a Certain Section

    I need a JavaScript script to only affect a certain section of my page. Is it possible that I could put that part of my page in a DIV or a FRAME to get this to work? How would I do this?

    Here is my script:

    Code:
    <script>
    function random_all(){
    var myrandom=Math.round(Math.random()*(document.links.length-1))
    window.location=document.links[myrandom].href
    }
    </script>
    
    <a href="javascript:random_all()">Random Link</a>
    As you can see, that would choose a random link from my entire page. If I want to make it choose from a section of my page, what would I do? (there are a lot of links on this page, and I don't want to assign number to each and every one of them, and then choose a random number)

  • #2
    what's the effect you're trying to achieve? is there a style change going on? Or are you changing the link? The background? What's it do?

    Comment


    • #3
      Code:
      <script>
      function random_some(){
      var anchors=document.getElementById('someContainer').getElementsByTagName('a');
      var myrandom=Math.[b]floor[/b](Math.random()*(anchors.length-1))
      window.location=anchors[myrandom].href
      }
      </script>
      
      <div id='someContainer'>
      <a href='puppies'>Cute!</a>
      </div>
      
      <a href='server/side/code/that/does/the/same/thing/because/you/care/about/accessibility' onclick='random_some();return false'>Random</a>

      Comment

      Working...
      X