jquery not recognising new svg instance (loaded from ajax)
My project revolves around an interactive svg map.
When i click a region.. ajax updates the container div with a new svg map. All looks good.
My current task is to update a secondary div with the name of the current hovered svg path (region) of the current map.
This works completely fine until i click a region and ajax updates the map to a new map.
The secondary div stops updating and stays frozen on the last piece of hovered data. E.g. the jqery code that handles this task stops working, but the rest (ajax) works fine.
This is likely a simple problem and purely down to my lack of knowledge
. I've made the following video to give some context.
here is the code (only important bits)
- $(function() {
- $( ".region" ).mouseover(function() {
- var regionLocation = 'location text';
- $("#location .path").html("location text");
- })
- .mouseout(function() {
- $("#location .path").html('location text');
- });
- });
I assume that this code needs to check to see if an svg instance exists every time it fires, rather than only interpreting the first instance that is loaded with the page.
Any ideas on how to do this? Thanks