Show list of colour options on hover of any of table
This is my table:
<table id="tblData">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria Anders</td>
<td>30</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Francisco Chang</td>
<td>24</td>
<td>Mexico</td>
</tr>
</table>
I want to show a list of colors on hover of any of the td's of the table.
List is a div card. Like this:
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container">
<label>Red</label>
</div>
<hr />
<div class="grey-hover container">
<label>Grey</label>
</div>
<hr />
<div class="green-hover container">
<label>Green</label>
</div>
<hr />
<div class="blue-hover container">
<label>Blue</label>
</div>
</div>
Here is what I tried:
$("#tblData tr:has(td)").click(function (e) {
$("#tblData td").removeClass("highlight");
var clickedCell = $(e.target).closest("td");
clickedCell.hover(function () {
$('.hover-div').removeClass('hidden');
}, function () {
$('.hover-div').addClass('hidden');
});
});
The problem here is that the div is appearing on the selected item on hover but the end of page. I want it to appear where ever the pointer is.
Here is the fiddle: https://jsfiddle.net/maverick6912/xpvt214o/957635/
Any help would be really appreciated. Thanks!
jquery html css
add a comment |
This is my table:
<table id="tblData">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria Anders</td>
<td>30</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Francisco Chang</td>
<td>24</td>
<td>Mexico</td>
</tr>
</table>
I want to show a list of colors on hover of any of the td's of the table.
List is a div card. Like this:
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container">
<label>Red</label>
</div>
<hr />
<div class="grey-hover container">
<label>Grey</label>
</div>
<hr />
<div class="green-hover container">
<label>Green</label>
</div>
<hr />
<div class="blue-hover container">
<label>Blue</label>
</div>
</div>
Here is what I tried:
$("#tblData tr:has(td)").click(function (e) {
$("#tblData td").removeClass("highlight");
var clickedCell = $(e.target).closest("td");
clickedCell.hover(function () {
$('.hover-div').removeClass('hidden');
}, function () {
$('.hover-div').addClass('hidden');
});
});
The problem here is that the div is appearing on the selected item on hover but the end of page. I want it to appear where ever the pointer is.
Here is the fiddle: https://jsfiddle.net/maverick6912/xpvt214o/957635/
Any help would be really appreciated. Thanks!
jquery html css
add a comment |
This is my table:
<table id="tblData">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria Anders</td>
<td>30</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Francisco Chang</td>
<td>24</td>
<td>Mexico</td>
</tr>
</table>
I want to show a list of colors on hover of any of the td's of the table.
List is a div card. Like this:
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container">
<label>Red</label>
</div>
<hr />
<div class="grey-hover container">
<label>Grey</label>
</div>
<hr />
<div class="green-hover container">
<label>Green</label>
</div>
<hr />
<div class="blue-hover container">
<label>Blue</label>
</div>
</div>
Here is what I tried:
$("#tblData tr:has(td)").click(function (e) {
$("#tblData td").removeClass("highlight");
var clickedCell = $(e.target).closest("td");
clickedCell.hover(function () {
$('.hover-div').removeClass('hidden');
}, function () {
$('.hover-div').addClass('hidden');
});
});
The problem here is that the div is appearing on the selected item on hover but the end of page. I want it to appear where ever the pointer is.
Here is the fiddle: https://jsfiddle.net/maverick6912/xpvt214o/957635/
Any help would be really appreciated. Thanks!
jquery html css
This is my table:
<table id="tblData">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Maria Anders</td>
<td>30</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>Francisco Chang</td>
<td>24</td>
<td>Mexico</td>
</tr>
</table>
I want to show a list of colors on hover of any of the td's of the table.
List is a div card. Like this:
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container">
<label>Red</label>
</div>
<hr />
<div class="grey-hover container">
<label>Grey</label>
</div>
<hr />
<div class="green-hover container">
<label>Green</label>
</div>
<hr />
<div class="blue-hover container">
<label>Blue</label>
</div>
</div>
Here is what I tried:
$("#tblData tr:has(td)").click(function (e) {
$("#tblData td").removeClass("highlight");
var clickedCell = $(e.target).closest("td");
clickedCell.hover(function () {
$('.hover-div').removeClass('hidden');
}, function () {
$('.hover-div').addClass('hidden');
});
});
The problem here is that the div is appearing on the selected item on hover but the end of page. I want it to appear where ever the pointer is.
Here is the fiddle: https://jsfiddle.net/maverick6912/xpvt214o/957635/
Any help would be really appreciated. Thanks!
jquery html css
jquery html css
edited Nov 22 '18 at 12:42
Julian Stark
1,2681426
1,2681426
asked Nov 22 '18 at 11:08
Umang SrivastavaUmang Srivastava
169
169
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Add this code lines :
$("#tblData tr:has(td)").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
//Other lines...
}
Note: see full code,here is more changes.
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429616%2fshow-list-of-colour-options-on-hover-of-any-td-of-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add this code lines :
$("#tblData tr:has(td)").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
//Other lines...
}
Note: see full code,here is more changes.
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
add a comment |
Add this code lines :
$("#tblData tr:has(td)").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
//Other lines...
}
Note: see full code,here is more changes.
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
add a comment |
Add this code lines :
$("#tblData tr:has(td)").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
//Other lines...
}
Note: see full code,here is more changes.
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
Add this code lines :
$("#tblData tr:has(td)").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
//Other lines...
}
Note: see full code,here is more changes.
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
$(document).ready(function () {
//making cursor a hand pointer
$("#tblData tr:has(td)").mouseover(function (e) {
$(this).css("cursor", "pointer");
});
//highlighting cells with chosen color.
$("#tblData td").click(function (e) {
$( '#parent_hover' ).css({'top': e.pageY,'left': e.pageX});
$('.hover-div').addClass('hidden');
$('.hover-div').removeClass('hidden');
$(this).removeClass("highlight");
$("#tblData td").mouseover(function(){
$('.hover-div').addClass('hidden');
})
});
});
#parent_hover {
visibility:visible!important;
}
.hidden{
display:none;
}
.hover-div{
position:absolute;
z-index:100;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #ccd;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:nth-child(odd) {
background-color: #ddeedd;
}
.highlight {
background-color: Yellow;
color: Green;
}
.red {
background-color: #e53935;
color: white;
}
.green {
background-color: #43A047;
color: white;
}
.grey {
background-color: #546E7A;
color: white;
}
.wrapper {
text-align: center;
}
.button {
background-color: #1976D2; /* Green */
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button:hover {
background-color: #1976D2; /* Green */
color: white;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #1976D2;
}
.card {
/* Add shadows to create the "card" effect */
height: auto;
width: 60px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
background-color:white;
}
.container {
padding: 2px 16px;
}
.hidden {
visibility:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<table id="tblData">
<tr><th>ID</th><th>Name</th><th>Age</th><th>Country</th></tr>
<tr><td>1</td><td>Maria Anders</td><td>30</td><td>Germany</td></tr>
<tr><td>2</td><td>Francisco Chang</td><td>24</td><td>Mexico</td></tr>
</table>
<div class="hover-div card hidden" id="parent_hover">
<div class="red-hover container"><label>Red</label></div>
<hr />
<div class="grey-hover container"><label>Grey</label></div>
<hr />
<div class="green-hover container"><label>Green</label></div>
<hr />
<div class="blue-hover container"><label>Blue</label></div>
</div>
edited Nov 22 '18 at 13:07
answered Nov 22 '18 at 12:12
EhsanEhsan
9,67931129
9,67931129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429616%2fshow-list-of-colour-options-on-hover-of-any-td-of-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown