Button to add inputs to container dynamically

so i enable dev mode create a box and a container #button1 and #box1
then i add this code

$w.onReady(function () {
    let inputCounter = 1; // Track input sets

    $w("#button1").onClick(() => {
        let newInputId = `input${inputCounter}`;
        let newRemoveId = `remove${inputCounter}`;

console.log("Button clicked!"); // Debugging


        // Create a new input field
        let newInput = `<div id="set${inputCounter}" class="input-set" style="margin-bottom:10px;">
            <input type="text" id="${newInputId}" placeholder="Enter value" class="wix-style-input" style="padding:5px;"/>
            <button id="${newRemoveId}" class="remove-btn" data-id="${inputCounter}" style="margin-left:5px; padding:5px;">Remove</button>
        </div>`;

        $w("#box1").html += newInput; // Append new input set

        inputCounter++;

        // Add event listener for remove buttons
        setTimeout(() => {
            $w("#box1").onClick((event) => {
                if (event.target.classList.contains("remove-btn")) {
                    let id = event.target.getAttribute("data-id");
                    $w(`#set${id}`).remove();
                }
            });
        }, 100);
    });
});

i get button clicked but no inputs added to the container box and no real message on dev tools

what’s the way to append the html either with new inputs or text to add content to the box1 when someone clicks on button1

here is a basic idea of what i want to do

<!DOCTYPE html>
<html lang="en">
<head>

    <title></title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

    <button id="addContentButton" >Add Content</button>

    <div id="contentContainer"style="border: 1px solid red;">
    
    </div>

<script>
       
        $(document).ready(function() {
            $('#addContentButton').click(function() {
                // HTML content to append
                var newContent = "<div class='new-content'>New Content Added: " + new Date().toLocaleString() + "</div>";

                // Append content to the container
                $('#contentContainer').append(newContent);
            });
        });
</script>

</body>
</html>

anyone? si this forum very active like php or python forums?

Hi, @Angel_A !!

It seems that the misunderstanding may come from the fact that Wix’s Velo (SDK) uses a syntax similar to jQuery, such as $w. However, in Velo (SDK), programming is not typically done in a way that mixes with direct DOM manipulation, as you described.

Instead, $w is used to select elements that have been dragged and dropped onto the Wix site, and those elements are then manipulated using Velo (SDK). If you find it easier to design using standard HTML, it might be faster to use an iframe (HTML Component) or Custom Elements, where you can write regular HTML and embed it within your Wix site.

Wix sites can communicate with these embedded elements using APIs like postMessage, allowing for seamless message exchanges. This means that changes occurring inside the embedded elements can be transmitted to the Wix page code, and conversely, changes on the Wix page can be transmitted to the embedded elements.

In any case, it may be beneficial to deepen your understanding of Velo (SDK) to make the most of its capabilities. :innocent:

In your case, i would say → it would be better to describe what exactly you want to achieve.
Show some pics of what you want to create and how you expect your endresult/final setup to be.
How should it work and whats the background behind.

Taking a look onto your code you can clearly see that you are not an experienced code, but you try to do your best.

What exactly you attempted to generate here…

The question will be if you need the html-component at all, depending what you want to create. Like already told by ONEMORETIME → Wix has it’s own working selfenclosed ecosystem, where you can’t use HTML and CSS coding just like that (i mean yes you can, but you have to know how).

Also already mentioned by ONEMORETIME → you of course can use the HTML-Component on your page to generate HTML-CODE and CSS codes, but you will have also to code a COMMUNICATION-BRIDGE between your HTML-ELEMENT and your WIX-PAGE.

So maybe first you try to explain what you want to generate.