How can I maintain the hover color on a button with a text label even when hovering over the text label?

I need help creating a button with a text label that both respond to clicks and have a hover color. The current code I have works, but the hover color is lost when hovering over the text label. How can I modify the code to maintain the hover color even when over the text label?

<!DOCTYPE html>
<style>
#resetButton {
  cursor: pointer;
  fill: #FFF68F;
}
#resetButton:hover {
  cursor: pointer;
  fill: #FFFF00;
}
</style>
<div id = "main"> </div>
<script src = "http://d3js.org/d3.v3.min.js"> </script>
<script>
var svg = d3.select('#main')
    .append('svg')
var g = svg.append("g")
  .attr({id: "resetButton"})
g.append('circle') // reset button
  .attr({cx: 100, cy: 100, r: 25})
  .attr({id: "resetButton"})
  .attr({onclick: "doSomething()" })
g.append('text') // button label
  .attr({x: 100, y: 95})
  .attr({fill: "black"})
  .attr({"font-size":  20})
  .attr({"text-anchor": "middle"})
  .text('R')
  .attr({onclick: "doSomething()" })
doSomething = function() {
  alert("Reset")
}
</script>

Answer №1

Disable pointer events on the text element.

g.append('text') // button label
  .attr({"pointer-events": "none"})
  ...

Check out the demonstration here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Resolving Problem of Jumping When 'invalid-feedback' Appeared in Bootstrap 4 Input

There is an input with an add-on and a customized focus that includes a '%' at the end of the field, which is working fine. However, there is a small issue where the error message causes the input to jump when clicked in or out. To see the issue ...

show the text input within a span element, encountering issues with its width

My goal is to create an input text field that looks exactly like a span element. I want the user to be able to enter text without realizing they are typing in a field. I have made some progress, but the main issue now is with the width of the input field. ...

Concealing overflow in an SVG element with absolute positioning

Looking to hide the parts of the circle that extend beyond the shadowed container. Utilizing bootstrap-4 for this project. body { overflow: hidden; } .container { margin-top: 5%; width: 1200px; height: 625px; border-radius: 4px; background- ...

Synchronizing Events across Two JavaScript Applications

In my game app (using Electron) and web app (testing on Android Chrome), they communicate through a websocket server to coordinate a countdown. I've noticed that in environments with low latency, the synchronization is fine. However, when there is mor ...

Troubleshooting video streaming loading issues caused by 404 errors in URL paths with videojs

I've been successfully using the video.js library to stream live video. Everything was going well until after a while, the URL started throwing a 404 error during streaming, causing the entire player to get stuck on loading. Now I'm looking for a ...

Shopping cart has encountered an issue with storing the data correctly

While I've managed to successfully integrate another service, the challenge now lies in implementing the logic for correctly generating cart items. My goal is to increment the quantity of items in the cart by one with each function call, but it seems ...

transitioning backwards upon the removal and addition of classes in vue

Currently, I am working on creating a help button that triggers a help-dialogue box with some animations when clicked. This is the template I am using: <template> <div class="help"> <button v-if="theme" class=" ...

Retrieve the value of an attribute within a controller function that is not a directive

Here is some HTML content, <button data-href="helloworld">Show href Value</button> And here is some Javascript content, $("body").on('click', 'button', function(){ console.log($(this).attr("data-href")); }); When exe ...

Similar Functionality to jQuery's .load() in REACT

I'm currently diving into the world of React, attempting to transition a PHP + jQuery Page to React (minus the jQuery). However, given the intricate complexity of the page, I won't be able to migrate everything at once. As a result, I need to sta ...

The callback function in JavaScript seems to be missing without ever being executed

I have a SendMail function using nodemailer that successfully sends emails, but the callback function logging "mail sent" is not getting executed. Any suggestions on what might be causing this? var email = '<a href="/cdn-cgi/l/email-protection" cla ...

Can I expect the same order of my associative array to be preserved when transitioning from PHP to Javascript?

While using PHP, I am executing a mysql_query with an ORDER BY clause. As a next step, I am going through the results to construct an associative array where the row_id is set as the key. After that, I am applying json_encode on that array and displaying ...

Creating a Loop with JavaScript through a List

My current API response format is: "imagePath": "path1", Here is the JavaScript code I am using: <div className="flexAlignCenterJustifyCenter"> {event.imagePath ? ( <img src={event.imagePath} onErro ...

Troubleshooting issues with resizing multiple Echarts in React

I'm facing an issue with resizing Echarts components when the window size changes. I have two components rendered, but only one of them is able to resize properly. Below is the source code for your reference - you can observe the problem by resizing y ...

Uncontrolled discord bot flooding with messages despite being set to send messages only once every 60 seconds

const Discord = require('discord.js'); const { Client, MessageAttachment } = require('discord.js'); const client = new Discord.Client(); client.once('ready', () => { console.log("Ready!") }) client.on(&apos ...

When the condition within the click function is met, concatenate the variable

I'm currently working on a function that involves adding "http://" to the variable 'bar' if it's not already included. This modified 'bar' value will then be sent via ajax to be inserted into the database and also displayed ba ...

Using jQuery to count children and show the outcome when hovering

I have implemented an alphabetical search functionality for products. When a letter is clicked, all products starting with that letter are displayed. However, I want to display the selected letter at the top and hide the rest of the letters. Should I use ...

What is the reason for the ineffectiveness of percentage padding/margin on flex items in Firefox and Edge browsers?

I am trying to create a square div within a flexbox. Here is the code I have used: .outer { display: flex; width: 100%; background: blue; } .inner { width: 50%; background: yellow; padding-bottom: 50%; } <div class="outer"> <div c ...

Employing the findOne method repeatedly in a loop can significantly slow down operations in Node.js

Currently, I am working on a project using Node.js in conjunction with MongoDB, specifically utilizing Monk for database access. The code snippet I have is as follows: console.time("start"); collection.findOne({name: "jason"}, function(err, document) { ...

Is there a way to override the JSON.stringify method within the JSON class of a TypeScript project without using a custom call?

Dealing with a React Native and TypeScript app here. I keep encountering an error from Fabric every week: "JSON.stringify cannot serialize cyclic structures." The frustrating part is that the error seems to pop up randomly, without any specific scenario tr ...

Tips for extracting data from a JQuery table with Python

My goal is to extract information from the top ten items on a manga website using Python Selenium/BeautifulSoup. However, I am facing challenges due to the website loading its content through a jquery script. The tutorials and guides I have followed do not ...