I am trying to create a table that allows users to click on a box and unlock the next column.
Initially, I set it up with two tds and it worked perfectly. However, when I tried to replicate it, the functionality didn't work as expected.
My idea is to have a TD with a specific class that can be clicked. Upon clicking, the JavaScript should enable users to click on the next tds or even the next column, changing their class to clickable like the previous one, and then making the current one non-clickable to prevent clicking again.
This is the code snippet for 2 tds:
<td>
<div style="position: relative;" class="can-select1">
<img src="http://lkimg.zamimg.com/images/guides/ability-marker.png" style="vertical-align: middle;" class="can-select">
<div class="can-select-text">1</div>
</div>
</td>
<td>
<div style="position: relative;" class="nothing1">
<img src="http://lkimg.zamimg.com/images/guides/ability-marker.png" style="vertical-align: middle;" class="nothing">
<div class="can-select-text">2</div>
</div>
</td>
JavaScript:
$('.can-select1').click(function(e){
$(this).addClass("is-selected");
$(this).find('.can-select').addClass("is-selected");
$(this).children('.can-select-text').addClass("is-selected");
var nextTd;
nextTd=$(this).parent().find('.nothing1');
nextTd.find('.nothing').addClass("can-select1");
nextTd.addClass("can-select1");
nextTd.removeClass('nothing1')
});
CSS:
.can-select1 {
cursor:pointer;
opacity:0.4;
}
.can-select-text{
opacity: 0;
position: absolute;
top: 0;
left: 0;
text-align: center;
width: 32px;
font: bold 13px/32px 'Trebuchet Ms';
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.6); color: #111;
}
.is-selected {
cursor:default;
opacity:1.0;
}
.nothing1{
cursor:default;
opacity:0;
}
JSFIDDLE for 2 td: http://jsfiddle.net/p3Q7Z/5/
JSFiddle for table: http://jsfiddle.net/p3Q7Z/6/