473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How can I get all occupied cells to highlight upon clicking on them?

74 64KB
Here is HTML code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3.     <head>
  4.         <title>@Model.PageTitle</title>
  5.         <link href="~/Styles/Home.css" rel="stylesheet" />
  6.     </head>
  7.  
  8.     <body>
  9.  
  10.             <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  11.             <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
  12.             <script src="~/Scripts/Home.js"></script>
  13.  
  14.             <div class="home">
  15.  
  16.                 <div class="board">
  17.                     <div class="row">
  18.                         <div class="cell piece red"></div>
  19.                         <div class="cell piece red"></div>
  20.                         <div class="cell piece red"></div>
  21.                         <div class="cell piece red"></div>
  22.                         <div class="cell piece red"></div>
  23.                         <div class="cell piece red"></div>
  24.                         <div class="cell piece red"></div>
  25.                         <div class="cell piece red"></div>
  26.                     </div>
  27.                     <div class="row">
  28.                         <div class="cell piece red"></div>
  29.                         <div class="cell piece red"></div>
  30.                         <div class="cell piece red"></div>
  31.                         <div class="cell piece red"></div>
  32.                         <div class="cell piece red"></div>
  33.                         <div class="cell piece red"></div>
  34.                         <div class="cell piece red"></div>
  35.                         <div class="cell piece red"></div>
  36.                     </div>
  37.                     <div class="row">
  38.                         <div class="cell"></div>
  39.                         <div class="cell"></div>
  40.                         <div class="cell"></div>
  41.                         <div class="cell"></div>
  42.                         <div class="cell"></div>
  43.                         <div class="cell"></div>
  44.                         <div class="cell"></div>
  45.                         <div class="cell"></div>
  46.                     </div>
  47.                     <div class="row">
  48.                         <div class="cell"></div>
  49.                         <div class="cell"></div>
  50.                         <div class="cell"></div>
  51.                         <div class="cell"></div>
  52.                         <div class="cell"></div>
  53.                         <div class="cell"></div>
  54.                         <div class="cell"></div>
  55.                         <div class="cell"></div>
  56.                     </div>
  57.                     <div class="row">
  58.                         <div class="cell"></div>
  59.                         <div class="cell"></div>
  60.                         <div class="cell"></div>
  61.                         <div class="cell"></div>
  62.                         <div class="cell"></div>
  63.                         <div class="cell"></div>
  64.                         <div class="cell"></div>
  65.                         <div class="cell"></div>
  66.                     </div>
  67.                     <div class="row">
  68.                         <div class="cell"></div>
  69.                         <div class="cell"></div>
  70.                         <div class="cell"></div>
  71.                         <div class="cell"></div>
  72.                         <div class="cell"></div>
  73.                         <div class="cell"></div>
  74.                         <div class="cell"></div>
  75.                         <div class="cell"></div>
  76.                     </div>
  77.                     <div class="row">
  78.                         <div class="cell piece black"></div>
  79.                         <div class="cell piece black"></div>
  80.                         <div class="cell piece black"></div>
  81.                         <div class="cell piece black"></div>
  82.                         <div class="cell piece black"></div>
  83.                         <div class="cell piece black"></div>
  84.                         <div class="cell piece black"></div>
  85.                         <div class="cell piece black"></div>
  86.                     </div>
  87.                     <div class="row">
  88.                         <div class="cell piece black"></div>
  89.                         <div class="cell piece black"></div>
  90.                         <div class="cell piece black"></div>
  91.                         <div class="cell piece black"></div>
  92.                         <div class="cell piece black"></div>
  93.                         <div class="cell piece black"></div>
  94.                         <div class="cell piece black"></div>
  95.                         <div class="cell piece black"></div>
  96.                     </div>
  97.                 </div>
  98.  
  99.             </div>
  100.  
  101.     </body>
  102.  
  103. </html>




Here is JavaScript mixed with JQuery code

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function ()
  2. {
  3.     var cells = $(".cell");
  4.     var colorCount = 0;
  5.  
  6.     for (var i = 0; i < cells.length; i++)
  7.     {
  8.         var cell = $(cells[i]);
  9.         var isDark = colorCount % 2 == 0;
  10.         var isNextRow = (i + 1) % 8 == 0;
  11.         colorCount += isNextRow ? 2 : 1;
  12.         cell.css("background-color", isDark ? "navy" : "white"); 
  13.     }
  14.     $(".cell piece red").click(function(){
  15.         $(".this").css("background-color", "yellow"); 
  16.     });
  17.  
  18. });

Here is my CSS codes

Expand|Select|Wrap|Line Numbers
  1. .home > .board
  2. {
  3.     display: table;
  4.     border: 1px solid black;
  5. }
  6.  
  7. .home > .board > .row
  8. {
  9.     display: table;
  10. }
  11.  
  12. .home > .board > .row > .cell
  13. {
  14.     width: 80px;
  15.     height: 80px;
  16.     border: 1px solid black;
  17.     display: inline-block;
  18. }
  19.  
  20. .piece
  21. {
  22.     background-size: 75px 75px;
  23.     background-repeat: no-repeat;
  24.     background-position: center;
  25.     background-origin: content-box;
  26. }
  27.  
  28. .red
  29. {
  30.     background-image: URL('../images/red.png');
  31. }
  32.  
  33. .black
  34. {
  35.     background-image: URL('../images/black.png');
  36. }
Feb 23 '17 #1
3 1040
Dormilich
8,658 Expert Mod 8TB
What is the problem you encounter?
Feb 24 '17 #2
dseals22
74 64KB
I can't get the red and blue checkers to highlight when I click on them?
Feb 24 '17 #3
dseals22
74 64KB
Can you help me @Dormilich
Feb 24 '17 #4

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

Similar topics

5
by: Harry | last post by:
CSS Description: Table contains a column of td cells with links. Achieved: 1. Entire link cells highlight when hovered. 2. The entire area of these cells are clickable. Problem:
2
by: Enjoy Life | last post by:
We have an ASP site that hits up an Access database of categories of products and products. (e.g. Categories = Napkins, Tablecloths; Products = 20x20 Napkins, 21x21 Napkins, 54x54 Tablecloths,...
1
by: Yeah | last post by:
I have a multiple choice quiz where I would like to use CSS to change the color of the answers upon clicking them. I would like to present the right and wrong answers up front, rather than direct...
2
by: chrisse_2 | last post by:
Hi, I am working with images which vary depending on what record you are looking at. The images are linked into my database using vba code. I would like the user to be able to double click on...
3
by: David | last post by:
Hi, I have 3 buttons on a asp.net page. They are exactly the same except for the name. Two of the buttons works but the third one does not respond to the clicking. Here is the code: <tr> <td...
1
by: Fir5tSight | last post by:
Hi All, This seems to be a difficult problem for me. Hope you can help me out... I have a program whose major part is a grid that displays several columns from data obtained from a stored...
0
by: bh | last post by:
I am working on a calendar application that requires me to let the user select a range of adjacent cells by: 1-clicking in the start cell (start of range) 2-holding down the mouse key...
5
by: Alex | last post by:
Hello, I hope I can explain this properly. I'm writing an application with a tabbed-based navigation, and a form which gets filled out by users will be split into 5 subtabs. What I need is...
1
by: pipet2002 | last post by:
how can i send values from one page to another upon clicking a button which links me to that page
2
by: SwatiGV | last post by:
I want to update the subform upon clicking a button (Run) in the main form. The Run button on the main form is updating a query(Filter Region). This query is the Source Object of the Subform. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.