How to Disable and enable onclick function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rosetattoo
    New Member
    • Jan 2015
    • 2

    How to Disable and enable onclick function

    I have a 50 onclick images in my local page I want only to enable 10 and the rest will be disabled, and each time I load a new set of 10 images will be enable...??

    someone help me :(
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    is there any algorithm that determines which 10 of the 50 images to enable?

    Comment

    • rosetattoo
      New Member
      • Jan 2015
      • 2

      #3
      A friend from Stackoverflow give me this code:


      Here is the sample code of how to enable 10 images

      and out put will in console should be:


      I try the codes but this is what ive got:

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      <script src="jQuery 1.11.2.js"> </script>
      <script >
       $(document).redy(function(){
      	 
      var images = $(".clickimage");
      
      //remove attr onclick after 10th items
      for(var i=10;i<images.length;i++){
          $(images[i]).attr('onclick','');
      }
       });
       
       </script>
      </head >
      
      <body>
      <form id="form1" runat="server">
      <div>
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
      <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
      
      </div></form>
      </body>
      </html>
      Last edited by Dormilich; Jan 28 '15, 10:01 AM. Reason: please use code tags when posting code

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I try the codes but this is what ive got:
        are there any problems?

        PS. using the onclick attributes is a really outdated way of handling events.

        Comment

        Working...