I have the following code part which my friend coded for a project and it uses jQuery library. I have no idea how to put this in Javascript so I can remove jQuery from the project.
function generateButtonClicked() {
disableGenerateButton();
var t = $(".speed").toArray(),
e = $(".status").toArray();
t.reverse(), e.reverse(), doNextBox(t, e)
}
function tripConnecting(t, e, n, a, c, l) {
$(c).html("Connecting"), tripDestination(n, function () {
tripMeasurement(t, e, n, a, c, l)
})
}
I used an online tool to convert this and it gave me the following code but it is not working properly. Any help would be greatly appreciated.
functiongenerateButtonClicked() {
disableGenerateButton().vart = (".speed").toArray(), e = (".status").toArray().t.reverse(), e.reverse(), doNextBox(t, e)
}
functiontripConnecting(t, e, n, a, c, l) {
(c).html("Connecting"), tripDestination(n, function () {
tripMeasurement(t, e, n, a, c, l)
})
}
asked May 6, 2020 at 14:06
Berglund
6772 gold badges8 silver badges22 bronze badges
2 Answers 2
Try this:
function generateButtonClicked() {
disableGenerateButton();
var t = Array.from(document.getElementsByClassName("speed")),
e = Array.from(document.getElementsByClassName("status"));
t.reverse(); // You could also add `.reverse` to the above declarations.
e.reverse();
doNextBox(t, e);
}
function tripConnecting(t, e, n, a, c, l) {
c.innerHTML = "Connecting";
tripDestination(n, function () {
tripMeasurement(t, e, n, a, c, l);
});
}
answered May 6, 2020 at 14:12
D. Pardal
6,6821 gold badge23 silver badges46 bronze badges
Method toArray from jQuery looks like:
const elements = Array.from(document.querySelectorAll('.speed'))
answered May 6, 2020 at 14:11
Mark Partola
6643 silver badges10 bronze badges
1 Comment
Mark Partola
$(c).html("Connecting") can be replaced as el.textContent = "Connecting" if it's not a collection. If it is just iterate themlang-js