S
S
Senseich2018-07-27 02:24:25
JavaScript
Senseich, 2018-07-27 02:24:25

Why doesn't jQuery work in getJSON?

I actually use the Jquery function - $.getJSON
Inside the function, for some reason, it does not see other jquery commands, although they do it everywhere on the Internet. I'm not a JS guru so see what's wrong here:

$(document).ready(function () {
        $.getJSON('curs_valut.json', function (data) {
            for (var i = 0; i < data.length; i++) {

                if (data[i].name == "USD") $('#usd').innerText = 'USD  ' + data[i].value.toFixed(2);
                if (data[i].name == "RUB") $('#rub').innerText = 'RUB  ' + data[i].value.toFixed(2);
            }
        });
    });


Actually, why does not work $('#usd').innerText,

but regular JS works document.getElementById("usd").innerText

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question