1

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

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly. Thanks for your time for looking into this.
Oh, wait! I mistakenly put a ; instead of a , in the 3rd line. I'm going to edit my answer.
2

Method toArray from jQuery looks like:

const elements = Array.from(document.querySelectorAll('.speed'))
answered May 6, 2020 at 14:11

1 Comment

$(c).html("Connecting") can be replaced as el.textContent = "Connecting" if it's not a collection. If it is just iterate them

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.