I have a map of the US states and counties in a SVG graphic rendered by D3. Each path have mouseover, mouseout and click events bound to it, as well as the FIPS county code set as the path ID.
I have a jQuery Autocomplete input where the user can input the name of a state or county. Given that input, which makes the corresponding FIPS ID available, how can I trigger the mouseover event programatically?
Steve Greatrex's solution worked for me until iOS 9, but not on iOS 10.
After debugging my code and some research it seems the issue was that the createEvent and initEvent functions are deprecated as per this documentation.
The new way of writing this is:
More explanation about the new way of creating and triggering events with event constructors can be found here.
You can achieve this by directly dispatching the event on the desired element:
See more detail in this blog post
Structure your javascript such that the the mouseover event calls a javascript function and then you can call that same function any time you want.
I figured out the answer. The main problem is D3 does not have an explicit
trigger
function as jQuery does. However, you can simulate it.Say you have a D3 path built via
and a mouseover event handler that changes the fill and stroke colors
Typically, most tutorials say to use
but actually using the value works as well. If you have an event handler that gets you the ID of the node, and trigger it via
will execute the mouseover event based on a dropdown selection