By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,948 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,948 IT Pros & Developers. It's quick & easy.

How to Disable and enable onclick function

P: 2
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 :(
Jan 28 '15 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 8,639
is there any algorithm that determines which 10 of the 50 images to enable?
Jan 28 '15 #2

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
  2. <html xmlns="">
  3. <head runat="server">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <script src="jQuery 1.11.2.js"> </script>
  7. <script >
  8.  $(document).redy(function(){
  10. var images = $(".clickimage");
  12. //remove attr onclick after 10th items
  13. for(var i=10;i<images.length;i++){
  14.     $(images[i]).attr('onclick','');
  15. }
  16.  });
  18.  </script>
  19. </head >
  21. <body>
  22. <form id="form1" runat="server">
  23. <div>
  24. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  25. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  26. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  27. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  28. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  29. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  30. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  31. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  32. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  33. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  34. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  35. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  36. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  37. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  38. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  39. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  40. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  41. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  42. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  43. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  44. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  45. <img id="1" class="clickimage" src="green.png" onclick="clickedItem()">
  46. <img id="2" class="clickimage" src="green.png" onclick="clickedItem()">
  47. <img id="3" class="clickimage" src="green.png" onclick="clickedItem()">
  49. </div></form>
  50. </body>
  51. </html>
Jan 28 '15 #3

Expert Mod 5K+
P: 8,639
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.
Jan 28 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.