0

I tried to use click on button:

@app.route("/")
def test_edition_open():
    return render_template("index.html")

my index.html file is:

<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>

The main part is just two buttons:

<div class = "counter">
    <button class = "minus">-</button>
    <div class = "result">1</div>
    <button class = "plus">+</button>
</div>

I tried to make My script.js file work in flask. The code is very simple, it should add numbers by clicking on button:

const plus = document.querySelectorAll('.plus');
const minus = document.querySelectorAll('.minus');
const result = document.querySelectorAll('.result');

function min()
{
    return function (ev)
    {
        if (ev.target.nextElementSibling.innerHTML > 0)
        {
            return --ev.target.nextElementSibling.innerHTML;
        }
    }
}

function pl()
{
    return function (ev)
    {
        return ++ev.target.previousElementSibling.innerHTML;

    }
}

minus.forEach(function (dominus)
{
    dominus.addEventListener('click', min());

})

plus.forEach(function (doplus)
{
    doplus.addEventListener('click', pl());
})

In https://playcode.io this code worked well. How should I solve this problem?

1 Answer 1

0

Make sure that script file successfully connected to html file. to check this add console.log("File Connected") in your script.js file. Then open your browser console to check that console message is logged correctly. If not then try to linked your static file correctly. How to set static_url_path in Flask application

Or you can put your Javascript code in html file using script tag. Something like this:

<script> your javascript code here</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.