score:3
Specificity
The ID has a higher specifity that the class.
Just make the selector more specific. important
is not recommended.
#circleSVG {
fill: red;
stroke: green;
}
#circleSVG.testCircle{
fill: orange;
opacity:0.25;
}
score:0
You are looking to change a class, but you also have an ID to define the svg color, so it's better to change the color of the ID when it's hover:
#circleSVG:hover{
fill: orange;
opacity:0.25;
}
To change the color by the ID, you can use
element = document.getElementById(id);
score:1
Why do you use JS to accomplish that? You can use only css.
#circleSVG {
fill: red;
stroke: green;
}
#circleSVG:hover {
fill: orange;
opacity: 0.25;
}
score:2
The problem is basically how the CSS selectors works.
Basically an id selector (#) is more specific than a class selector (.). So the "fill: orange" property in the class selector (.testCircle) is not being applied because the id selector (#testCircle) is more specific and also have a fill property. On the other hand, the opacity property is working because the id selector doesn't specify that property.
To fix this you can add "!important" as follow:
.testCircle{
fill: orange !important;
opacity:0.25;
}
Or even better, make your selector more specific:
#circleSVG.testCircle{
fill: orange !important;
opacity:0.25;
}
Source: stackoverflow.com
Related Query
- Some CSS styles not working on SVG
- Positioning svg x/y coordinates with css not working with iOS devices?
- CSS transform-origin not working for svg in safari
- Title Attribute not working for an SVG Rect on Safari
- d3.js - mouseover event not working properly on svg group
- D3 - Positioning tooltip on SVG element not working
- D3: Zooming/Panning Line Graph in SVG is not working in Canvas
- Breaking D3 in separate HTML, JS and CSS files not working
- SVG text element text-anchor="middle" not working in Firefox
- CSS transform rotate not working in internet explorer 11
- svg <a> element not working
- SVG Marker Not Working
- SVG not working in Firefox 18
- Svg scale() is not working on Edge(Not Edge Chronium)
- Select SVG elements using rectangle select box not working during zoom : d3.js
- add custom elements based on css styles not images to chart D3.js
- Svg semantic zoom not working on SVG in HTML
- zoom/pan with d3.js and svg not working
- d3.js v5.9.1 - some methods in this version are not working as expected
- SVG text path not working correctly in IE
- Mouse up event not working properly in SVG
- ng-click not working in D3 generated svg
- Adding image to svg container using d3 not working on FF and Safari
- d3.mouse not working properly on transformed SVG
- SVG Sprite Pattern Not Working in D3
- svg filter not working in mozilla firefox after zoom
- Mutiple force layouts in multiple svg in single page not working
- CSS3 - Transform-origin not working on SVG element in d3.js
- Position relative is not working in Safari 11 Dagre-d3 svg
- D3 Typescript SVG append not working
More Query from same tag
- d3 SVG Line elements not firing onclick event
- Half pie chart with multiple values
- Tooltip is going out of the box in d3 chart
- D3 updated data not propagated to mouseover event
- How come that D3.js can select an element that jQuery can't?
- D3.js event listeners cannot access "this" when ES6 arrow functions are used
- D3 set afterwards added node position
- D3: Merge JSON object entries
- D3: Y axis prints won't update with new data
- Flip d3js svg line
- How can I highlight an entire pathway in a D3 Sankey diagram?
- Uncaught TypeError: Cannot read property 'length' of undefined in example d3 code
- upgrading d3js from v3 to v4 causes zoom problems
- Manipulate Google GeoChart SVG with D3
- How to disable legend in nvd3 or limit it's size
- d3 line does not draw
- add custom class dynamically to dc.selectMenu; IE11 removes it
- Uncaught TypeError: Cannot read property 'position' of undefined (D3.JS)
- D3 Grouped Bar Chart From Arrays
- Dynamic filtering in D3 with HTML input
- Adding multiple objects to svg and adding drag behaviour issue
- Different Image Sizes in Force-Directed Images and Labels Layout in d3js
- Getting the max values from JSON in D3
- Series labels in Multi-line chart in d3.js
- D3 doesn't update Data
- Issue with multiple d3 graphs on same page
- d3.js: Handling multiple brushes
- Text element causing Rect element to recall mouseover event
- Suppress extreme outliers from d3plus box and whiskers plot drawing
- D3 Scale SVG children