Interact with elements across multiple SVG files using HTML

I have a website that consists of three SVGs. I am now looking to connect elements in these different SVGs by drawing simple lines between them.

My goal is to create a line from element1 (#element1) in svg1 to element6 in svg2.

Unfortunately, I am unable to merge all the SVGs together into one SVG object because each SVG is loaded dynamically and contains unique images.

As a result, I need to draw on the clean HTML DOM. Is this achievable?

Answer №1

As mentioned by @hungerstar, accomplishing that task can be quite simple. I would recommend using an embedded image in a similar way;

Check out this CodePen for experimentation

svg {
  border: red 1px solid;
}
svg line {
  stroke: red;
}
<svg width="300" height="300" viewBox="0 0 300 300">
  <image width="100" height="100" xlink:href="https://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" />
  <image width="100" height="100" xlink:href="https://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" x="200" y="200"/>
  <line fill="none" stroke-width="10" stroke-miterlimit="10" x1="50" y1="50" x2="250" y2="250"/>
</svg>

I hope this information proves to be useful. Thank you.

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

Can a snapshot be taken of a particular section of your website?

I'm curious to know if there is a method to capture an image from a specific part of a website and store it on the computer. Is this achievable? HTML <div id="red" color="red" width="100px" height="100px"></div> <div id="green" color= ...

Discover the concealed_elem annotations through the power of JavaScript

As I work on my new website, I am struggling with narrowing down the web code. I came across a solution that seems fitting for what I need, but unfortunately, I can't seem to make it work: I attempted the non-jQuery solution, however, I must be missi ...

Tips for effectively interpreting a json string

Trying to extract specific fields from a JSON string and display them on an HTML page, but encountering the following error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data This is the JSON being sent: { "Order0& ...

Examining a feature by solely utilizing stubs

I've been immersed in writing tests for the past few weeks. In my workplace, we utilize Mocha as our test runner and Chai for assertions, with Sinon for creating stubs. However, there's a recurring issue that's been bothering me. I've w ...

css background images are fully covered

Hey there! I recently created a CSS image that covers the entire background of my website. However, when I added a picture in the HTML, it doesn't show up because it's being overlapped by the CSS background. Check out my CSS code: { margin: 0 ...

Can Angular handle properties containing hyphens within them?

As I embark on creating my first complete Angular application, I encountered an interesting quirk. The model I am working with has a data structure that looks like this: { id: "12345", host: { name: "someHostServer", ip-addresses: ...

Strategies for obtaining newly updated data with every request and implementing a no-cache approach in Apollo GraphQL and Angular

Every time a request is made, we need a fresh value, like a unique nonce. However, I am facing issues while trying to achieve this with Apollo's Angular client. My initial solution was to utilize watchQuery with the no-cache strategy: this.apollo.wat ...

Invalid label detected - Syntax Error in the response from Jsonp/Ajax!

I have a snippet of code that I'm having trouble with. It's shown below: <script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript"> jQuery.getJSO ...

Dealing with Superagent and Fetch promises - Tips for managing them

Apologies for posing a question that may be simple for more seasoned JS programmers. I've been delving into superagent and fetch to make REST calls, as I successfully implemented odata but now need REST functionality. However, I'm facing confusio ...

Spin a sphere within a semicircle using html and css

I have been working on a project to animate a ball inside a crescent shape using HTML and CSS. You can check out my codepen here. However, I am facing an issue where the ball is currently stuck at the top of the crescent. I would greatly appreciate any as ...

Implementing mouse hover functionality for fieldset in EXTJS

I am looking to enhance the following code snippet by adding a mouse hover event that changes the background color of the fieldset item and displays an image next to it. Can someone assist me with this modification? var mainGroup = { ...

Using the directive in AngularJS and passing ng-model as an argument

Currently, I am creating a custom directive using AngularJs, and my goal is to pass the ng-model as an argument. <div class="col-md-7"><time-picker></time-picker></div> The directive code looks like this: app.directive(' ...

What is the best way to loop through children in an array using JavaScript?

I have an array that might look like this: arr1 = ["node1","children1","children1.1","children1.1.1"] or it could be arr2 = ["node1","children1"] and I am trying to convert it into the following JSON format: const data_arr1 = [{ title: "N ...

Creating an unordered list navigation using jQuery and JSON data

Help needed in creating a dynamic menu using ul and li tags. The menu structure will be based on JSON retrieved from the web server. How can I implement this menu with jQuery? var data = [ { "MenuId": "4fde524c-9f8e-4fc4-a7c1-aea177090299", "Par ...

Tips and tricks for locating the xpath of a header title using Selenium Webdriver and Java

Looking to locate the xpath of a header title that is only accessible through the 'inspect element' tab with its class and text content provided. The objective is to create an if statement to verify whether the page's title matches my desir ...

Prevent ajax requests from piling up using Jquery

There are two possible approaches to this situation. One is from the perspective of presentation, and the other is from a processing standpoint. The current setup involves a table of data. Various actions (such as typing a search query or clicking on diff ...

Exploring the Window.prompt() method in JavaScript

Take a look at this code snippet: <!DOCTYPE html> <html> <body> <p>Click the button to show the prompt box.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> funct ...

Passing PHP loop values to JavaScript

In my current project, I made a decision to avoid using a database and instead opted for files and folders. Each folder in a directory is represented as a button, clicking on which displays a list of files within that folder on the screen. Now, my challeng ...

What is the best way to transfer data from a component to a .ts file that contains an array?

I am currently developing a budgeting application and I have a component that is responsible for holding values that I want to pass to an array stored in a separate file. While I can retrieve data from the array, I am facing difficulty in figuring out how ...

Creating MySQL queries programmatically using data stored in a JSON object

Is it possible to construct a MySQL query dynamically from a JSON object with potentially empty values? For instance, starting with an object like this: { "a": 1 "b": "" "c": "foo" } we want to generate a query like the following (ignoring the emp ...