Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  116] [ 7]  / answers: 1 / hits: 32212  / 8 Years ago, thu, march 31, 2016, 12:00:00

I have used d3.js to draw some circles on an SVG container.



I have successfully set the mouseover behavior on these circles to print simple console messages. I see those console messages when I mouseover (and mouseout) so I know they are working properly.



However, instead of printing that console messages, I want to change the cursor to the hand when I mouseover them, and I want to change the cursor back to the normal arrow when I mouse out. Given my code below, how can I do it?



On mouseover, I know I need to change the style property cursor to pointer and on mouseout, I know I need to change it to default but I don't know the syntax of how I should do it. Can someone please explain it to me? Below is my code.



        var myCircle = svgContainer.selectAll(.dots)
.data(myDataList).enter().append(circle)
.attr(class, dots)
.attr(cx, function(d, i) {return d.centerX})
.attr(cy, function(d, i) {return d.centerY})
.attr(r, 5)
.attr(stroke-width, 0)
.attr(fill, function(d, i) {return red})
.style(display, block);



myCircle.on({
mouseover: function(d) {
console.log('Hello World!'); // What do I change this to?
},
mouseout: function(d) {
console.log('Goodbye World!'); // What do I change this to?
}
}
);

More From » css

 Answers
27

You can do it like this:



myCircle.on({
mouseover: function(d) {
d3.select(this).style(cursor, pointer);
},
mouseout: function(d) {
d3.select(this).style(cursor, default);
}
});


working code here



OR



you can simply work this out in the CSS.



myCircle.style('cursor', 'pointer')


[#62751] Monday, March 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 2 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;