Please replicate an element based on user input using Javascript

When I click on the ADD button, the text appears below but in the same column. There are 2 input fields.

  1. I have used:

    <input id="accordion_input" type="text"/>

  2. Another one is:

    <div id="accordion_body" class="panel-body"></div>

https://i.sstatic.net/t1qFV.png

So, when I fill up the input and div area and click the ADD button, I should appear. If I click the add button a second time, it should clone the first input data. Each cloned part of the data should show in a different column, not the same column. Like the image below:

https://i.sstatic.net/nUd2V.png

$(document).ready(function() {
  $('#Add_btn').click(function() {
$('#accordion_body').append($('#editableDiv').html());

var x = $("#accordion_input").val();
$("#accordion_title").append(x);
  });  
});
<html>
<head>
<title>404</title>
</head>

<body>
<input id="accordion_input" type="text">
<div id="editableDiv" contenteditable=""></div><br/>
<div id="acc_main" contenteditable="false" class="accordion-main">
  <div class="panel-group trash_removed" id="accordion" role="tablist" aria-multiselectable="true" contenteditable="false">
<div class="panel panel-default">
  <div class="panel-heading" role="tab" id="headingOne" contenteditable="false">
<h4 class="panel-title">
  <a id="accordion_title" style="display: block"></a>
</h4>


<div id="expandingCol" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne" style="display: block">
  <div id="accordion_body" class="panel-body"></div>
  
</div>
</br>

  </div>
</div>
  </div>
</div>
<button id="Add_btn">Add</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</body>
</html>

Answer №1

To ensure proper formatting, enclose the text in a <p> element or add a <br/> tag after each paragraph.

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

Stacked divs experiencing layout issues in Firefox browser

An innovative book animation has been crafted, showcasing flipping pages with a clever use of z-index to stack the pages. While everything displays correctly in the browser UI, an interesting situation arises when inspecting elements. In Firefox, selectin ...

A DIV element may not have any visible height, even when it contains content

My <div> contains multiple <img> elements, each wrapped in its own inner <div>. Despite setting the outer div's height to auto, it fails to adjust dynamically based on the content. To display the inner divs inline, I've applied ...

Can anyone suggest a method to block the execution of Javascript commands in the console?

Regarding the inquiry mentioned in the question title. Is it possible to prevent individuals from executing functions on my webpage using the console, even though it is not necessary? I have experimented with various methods, and the code below represent ...

Are HTML tables a viable fix for the problem with ng-repeat?

Let's talk about a fictional dataset that mirrors tabular data found in Excel. function SU(name: String, data: Array<any>) { this.name = name, this.data = data }; function Month(month: String, year: String, goal: Number, projection: ...

Encountering a problem with loading ajax data in jVectorMap

I'm currently facing an issue where I am unable to load data from visitors into a map created using the jvectormap plugin. This problem is really frustrating me as I can't seem to fetch the data through ajax, although it works fine when I input ...

Perform a search using indexOf method on JSON.stringify objects

I am attempting to determine whether a specific string exists in the following code: var test1 = '{"packageId":"1","machineId":"1","operationType":"Download"},{"packageId":"2","machineId":"2","operationType":"Download"}'; alert("found: " + test1 ...

"Maximizing battery life: Efficient video playback on iOS in low power

Summary: I am currently working on a website that features a video set as the background which autoplays. However, I have encountered an issue on iOS devices when "Low Power Mode" is activated - the video fails to play and instead displays a large "Play" i ...

`Unable to retrieve Shopify products using shopify-api-node`

I'm encountering a 403 error while trying to retrieve products from my custom Shopify app using the shopify-api-node module. Below is the code snippet I've put together based on a helpful discussion on Stackoverflow: const express = require(& ...

Prevent submission until all input fields are completed

Seeking guidance on a jQuery script to disable the submit button until all input fields are filled. Here is what I have so far: $(document).ready(function (){ if ($('#inputName, #inputEmail, #inputTel').val().length > 0) { $("input[type=su ...

How do I use Lodash chaining to filter an array of objects and map over an object containing arrays?

Here is the structure of my filter object: var filterUpdate = { assetClass: [{id: 1, name: 'photo'}, {id: 2, name: 'thumbnail'} ] vehicleType: [{id: 1, name: 'nissan'}] } Now, let's look at the dynamic state data with ...

Utilizing _.partial on a single-argument function

Currently, I am in the process of refactoring code within a react.js application. There is an element that utilizes Underscore.js _.partial on a function that already has one argument. Is there any real benefit to doing this? I can see how it works based ...

Tips for incorporating a return statement within a network request function that is already returning information pertaining to the request

Is there a way to retrieve the data extracted from within newReq.on('response', (response) => {? var request = require('request'); const cheerio = require('cheerio'); const { app, net, BrowserWindow } = require('elect ...

Tips for transforming a table column into an input field to retrieve the value and id of the field?

I have a set of data stored in the table provided below. My goal is to convert the table cell into an <input/> field once it is clicked. Following that, I want to send both the value and the id of the <input/> via an ajax request. Is this achie ...

Utilizing Angular's locale feature for currency formats

Exploring Angular (1.6.4) is a new adventure for me, and I have a task at hand to customize currency symbols across my webpage by configuring $locale in this Angular application. Currently, the code snippet looks like this: {{myCtrl.getPrice() | currency ...

What is the best way to center a Bootstrap login form within the viewport?

Struggling to get the login view centered on the screen, no matter what I try. As a newcomer to Bootstrap and coding, it's proving to be a challenge. Attempts to use align items center and justify haven't yielded the desired result. <h2 style ...

Aligning two divs vertically and adjusting the spacing between them

Currently dealing with a challenge regarding vertical alignment. I have two divs, one with dynamic height based on the browser size and the other with fixed height positioned at the bottom of the page. The second div also requires some margin. You can see ...

Performing simultaneous updates to multiple records using CAML/jQuery in Sharepoint (Batch updates)

I am working on updating multiple records in Share Point using jQuery and CAML queries. While it's easy to update a single record with the current code, I need to handle 20 Products simultaneously for this particular project. Instead of looping throug ...

Verify the REST call for access to Google APIs

Having issues with authenticating a REST request for Google APIs. Typically, Google provides client packages to handle this process. Currently using the Document Translation service which is still in preview, so unable to use the package. The documentatio ...

Error 500: Internal Server Issue Detected during AJAX Request in Laravel

I am having issues with fetching dependent select items using an ajax call. I want to display related 'groups' after selecting a 'class', but I keep getting a 500 internal server error in my console. Can someone please assist me in achi ...

what is the best way to create a wishlist feature using React.js

I'm working on creating a wishlist feature using React.js. My goal is to add an item to the wishlist when the user clicks the wish button, and mark it as liked by setting the boolean data "liked: true". Additionally, I want the item to be removed fr ...