Arranging a button input and customizing an SVG

If the starting and ending coordinates of a Bezier curve are made equidistant, it allows for duplication of Bezier curves.

By clicking the button, a second Bezier curve will appear below the first one, both being of the same size. This results in the two Bezier curves forming a perfect circle due to their equal dimensions.

I have encountered an issue where my Bezier Curve is causing the button to be positioned at the bottom of the screen. I have attempted using CSS and JavaScript setAttribute methods to address this problem but with no success. How can I ensure that my XHTML button is displayed above the SVG Bezier curve? Below is my HTML code snippet:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>SVG_Bezier_Curve</title>
      <link rel="stylesheet" type="text/css" href="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.css"/>
      <script language="javascript" src="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve_2.js">
      
      </script>
</head>
<body onload = "Setup()">
     <input type="button" id="Bezier_Curve_Button" onclick="Setup2()" value="Click Me!" position = "absolute" top = "100px"/>
     <svg xmlns="http://www.w3.org/2000/svg" id="My_SVG" position = "absolute" top = "200px" height="500px" width="600px">
     <path id="Bezier_Curve_1"/>
     <path id="Bezier_Curve_2"/>
     </svg>
</body>

Below is the corresponding JavaScript code:

    function Setup() {
    var Bezier_Curve_Identification;
    var Attribute_Name;
    var Attribute_Name_2;
    var Coordinate;
    var My_Properties;
    var Button_Identification;
    
    
    
    Attribute_Name = "d";
    Attribute_Name_2 = "style";
    My_Properties = "stroke: blue; stroke-width: 3; fill: none;";
    Coordinate = "M 375 200 A 50 50 0 0 1 475 200";
    Button_Identification = document.getElementById('Bezier_Curve_Button');
    Button_Identification.setAttribute = ("style", "top: 100px; height: 200px;");
    Bezier_Curve_Identification = document.getElementById('Bezier_Curve_1');
    Bezier_Curve_Identification.setAttribute(Attribute_Name, Coordinate);
    Bezier_Curve_Identification.setAttribute(Attribute_Name_2, My_Properties);
    
    
  
}

function Setup2() {
    
    var SVG_Data;
    var Retrieved_Data;
    var Bezier_Curve_1;
    var Bezier_Curve_2;
    var Counter;
    var Coordinate_Attribute;
    var Coordinate;
    var Style_Attribute;
    var Style_Details;
    var Bezier_Curve_Identification;
    
    SVG_Data = new XMLHttpRequest();
          SVG_Data.open("GET","http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.xq", true);
          SVG_Data.onreadystatechange = function () {
              if (SVG_Data.readyState == 4) {
              Retrieved_Data = SVG_Data.responseText;
              Retrieved_Data = Retrieved_Data.split("/");
              Counter = 0;
              Bezier_Curve_1 = Retrieved_Data[Counter];
              Counter += 1;
              Bezier_Curve_2 = Retrieved_Data[Counter];}
              Bezier_Curve_1 = Bezier_Curve_1.split("*");
              Counter = 0;
              Coordinate_Attribute = Bezier_Curve_1[Counter];
              Counter += 1;
              Coordinate = Bezier_Curve_1[Counter];
              Counter += 1;
              Style_Attribute = Bezier_Curve_1[Counter];
              Counter += 1;
              Style_Details = Bezier_Curve_1[Counter];
              Bezier_Curve_Identification = document.getElementById('Bezier_Curve_1');
              Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
              Bezier_Curve_Identification.setAttribute(Style_Attribute, Style_Details);
              Bezier_Curve_2 = Bezier_Curve_2.split("*");
              Counter = 0;
              Coordinate_Attribute = Bezier_Curve_2[Counter];
              Counter += 1;
              Coordinate = Bezier_Curve_2[Counter];
              Counter += 1;
              Style_Attribute = Bezier_Curve_2[Counter];
              Counter += 1;
              Style_Details = Bezier_Curve_2[Counter];
              Bezier_Curve_Identification = document.getElementById('Bezier_Curve_2');
              Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
              Bezier_Curve_Identification.setAttribute(Style_Attribute, Style_Details);
              
              };

SVG_Data.send();}

Finally, here is the relevant CSS code:

 #Bezier_Curve_Button {
position: absolute;
top: 100px;
left: 50px;
height: 100px;
width: 150px;}

Answer №1

It appears that there are several syntax errors present in the code you provided.

Specifically, elements such as <input> and <svg> should not have attributes like position or top. These declarations should be included in your CSS style sheet.

Furthermore, the adjustments you are trying to make within the script are incorrect. The following line is particularly problematic:

Button_Identification.setAttribute = ("style", "top: 100px; height: 200px;");

A more appropriate approach would be:

Button_Identification.style = "top: 100px; height: 200px;";

To help address these issues and guide you towards a solution, we have provided a functional code snippet below. This corrected version may offer some assistance in achieving your desired outcome.

function Setup() {
    var Bezier_Curve_Identification;
    var Attribute_Name;
    var Attribute_Name_2;
    var Coordinate;
    var My_Properties;
    var Button_Identification;
    
    Attribute_Name = "d";
    Attribute_Name_2 = "style";
    My_Properties = "stroke: blue; stroke-width: 3; fill: none;";
    Coordinate = "M 375 200 A 50 50 0 0 1 475 200";
    Button_Identification = document.getElementById('Bezier_Curve_Button');
    Button_Identification.style = "top: 100px; height: 200px;";
    Bezier_Curve_Identification = document.getElementById('Bezier_Curve_1');
    Bezier_Curve_Identification.setAttribute(Attribute_Name, Coordinate);
    Bezier_Curve_Identification.setAttribute(Attribute_Name_2, My_Properties);
}

Setup()
#Bezier_Curve_Button {
  position: absolute;
  top: 100px;
  left: 50px;
  height: 100px;
  width: 150px;
  border: 1px solid green;
}

#My_SVG {
  position: absolute;
  top: 200px;
  height: 500px;
  width: 600px;
  border: 1px solid orange;
}
<body>
  <input type="button" id="Bezier_Curve_Button" value="Click Me!"/>
  <svg id="My_SVG">
    <path id="Bezier_Curve_1"/>
    <path id="Bezier_Curve_2"/>
  </svg>
</body>

If you require additional assistance, please provide more details about what you expect the final outcome to look like, demonstrate it visually, and explain the expected behavior upon clicking the button. Enhancing your post with this information will enable us to offer more precise guidance.

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

The implementation of Axios cancel token failed to function properly in a real-time search feature within a React application

I'm currently developing a dynamic search feature using React, where users can input search terms and receive JSON results. I attempted to implement axios cancel token for this functionality, but it doesn't seem to be working properly and I' ...

Extrude a face in Three.js along its respective normal vector

My goal is to extrude faces from a THREE.Geometry object, and my step-by-step approach involves: - Specifying the faces to be extruded - Extracting vertices on the outer edges - Creating a THREE.Shape with these vertices - Extruding the shape using THREE.E ...

Opacity property not functioning properly in Internet Explorer 8

There seems to be an issue with adjusting the background opacity. style.css .divOpacity1 { position: absolute; z-index: 1; height: 2000px; width: 100%; background-color: #FFFFFF; top: 2px; left: 0px; opacity: 0.6; ...

Getting the toState parameter using the $transitions service in the latest version of the ui-router

In my project, I am currently utilizing ui-router version 1.0.0-alpha.3. Please note that the older events have been deprecated in this version. As a result, I am in the process of migrating from: $rootScope.$on('$stateChangeStart', (event, toS ...

Access cookie information within a Vue application by reading it within the router or component

There is a url (*/webapp/callback) in my vue.js app that gets redirected (http 302) from another application, bringing along some cookies. I'm trying to figure out how I can read these cookies when the component mounts and then store them in vuex stat ...

Hover shows no response

I'm having trouble with my hover effect. I want an element to only be visible when hovered over, but it's not working as expected. I've considered replacing the i tag with an a, and have also tried using both display: none and display: bloc ...

Using jQuery to duplicate elements by copying and pasting

I am facing a scenario where I need to dynamically create and manipulate a div element in my web application. The process involves appending the newly created div to another container upon clicking a button, followed by triggering a series of functions on ...

Trouble implementing media queries (code available)

Having trouble with my media queries, they're not working. Can someone please help me understand what's happening? Current screen size: 241 (chrome, ie, ff) CSS @media screen and (max-width: 500px) { body { width: 100%; ...

Clearing all the nested offspring elements within a highly nested one-dimensional array

I am working with a 1D deep nested array structure: nestedObj: [ { id: 1, parentId: null, taskCode: '12', taskName: 'Parent one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}, ...

Having trouble searching using CSS or XPath with Selenium Webdriver, but no issues when searching by ID or class

I am currently using Eclipse Mars along with JDK 1.8. Below is the code I have written: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public cla ...

Checking two promises in AngularJS to ensure they have both returned successfully

I am faced with a scenario where I need to execute actions as each promise returns individually, and perform another action once both promises have returned successfully. promise1.then(function() { // do something }) promise2.then(function() { // do some ...

retrieving multiple values in ajax call and processing them in controller function

I'm facing a challenge in Laravel when it comes to sending multiple input options (generated by a foreach loop) through an ajax call. The goal is to send multiple values and loop through them in the ajax call to effectively pass them to the controller ...

Getting URL Parameters in Angular JS

How should one go about retrieving URL parameters in Angular? For instance, consider this URL: http://example.com/mypage.html?product=1234®ion=4&lang=en Thank you ...

Is it possible to apply a complete style sheet to a single div element only?

I'm currently working on a website and I want to incorporate a dynamic bootstrap calendar. The issue I'm facing is that my site has its own style sheet, but the calendar comes with its own styles. When I try to integrate the two, it seems like el ...

Discover the Color's Value in Relation to a Different Color

When it comes to my CSS, I like to use .scss to make as many variables as possible. It's easy to create a variable for one color, like $primary-color. From there, I want to work with different shades of that color, which I can easily pinpoint using Ph ...

The quickest method to modify the anchor element's class depending on the query string

Requirement - I aim to accomplish this task using only pure JavaScript without any additional libraries, although I am open to using one if necessary. I need to assign an extra class to anchor elements that contain a query string of 'xyz=negate' ...

I attempt to demonstrate to my users, but unfortunately, it doesn't seem to be successful

My console.log is showing "undefined" for my users even though I can see them in my State. This issue started happening after implementing Redux - previously, it was working fine without Redux. Take a look at the code snippet from UserManagement.js: funct ...

Message displaying successful AJAX response

I'm currently updating my AJAX request to make it asynchronous, but I am wondering if there is an equivalent to var response = $.ajax({ in the success function. Previously, my code looked like this: var response = $.ajax({ type : "GET ...

Remove a property from an object using Object.assign()

Is there a way to remove a key using Object.assign() rather than setting the value to undefined in this scenario? In my code, I am utilizing .filter() to iterate through certain items. When a match is found, I aim to modify the x-property value while also ...

What is the best way to apply ng-style to a single element that was generated using $index within an ng-repeat loop

I am dealing with 2 directives: wa-hotspots and wa-tooltips. When the ng-mouseover event occurs on wa-hotspots, it takes the $index of wa-hotspot and adjusts the visibility and position of wa-tooltip using ng-class:on and ng-style="tooltipCoords" by matchi ...