0

I am new to web development and to get my some knowledge on this, I am working on a project https://jsfiddle.net/pz6tc3ae/30/ (Please try the project in chrome, some features don't work in other browsers). There are two tables in this project and on click on any cell in table 1, it triggers table 2 and if user clicks on an option in table 2, it changes the colour of clicked cell in table 1.

What I want to do is, add a feature in table 1 that when user clicks 3 times on a cell in table 1 the colour of the cell changes to a specfic/default colour.

I have done some research but being new to javascript and html5, I am not quite sure how to implement my research into the project I am working on, so any help is welcomed.

For example, reading on w3school: http://www.w3schools.com/tags/ev_ondblclick.asp I found double click function

<button ondblclick="myFunction()">Copy Text</button>

<script>
function myFunction() {
    document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>

Also, there was a useful answer given by Andy E on How do I listen for triple clicks in JavaScript? but I am not sure how to go about putting this in my project.

Thanks in advance and if my question was not clear please let me know.

5
  • 1
    Like this? jsfiddle.net/pz6tc3ae/38 Commented Feb 4, 2016 at 8:54
  • Yep, but instead of dialog, change the colour Commented Feb 4, 2016 at 8:59
  • would it be something like this: if (evt.detail === 3) { firstTableCells[i].style.background = "black" } Commented Feb 4, 2016 at 9:00
  • here's a similar post stackoverflow.com/questions/15666660/… Commented Feb 4, 2016 at 9:01
  • Thanks Tan, how would I change the colour Commented Feb 4, 2016 at 9:02

1 Answer 1

0

Based on @Ryan.Hunt comment/help I was able to solve my problem using this:

 if (evt.detail === 3) {
            actionCell.style.background = '#000000';
        }

https://jsfiddle.net/5xrqpggh/

I hope it will help future readers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.