D
D
Dubolom Unicellular2020-04-23 22:52:04
JavaScript
Dubolom Unicellular, 2020-04-23 22:52:04

Why doesn't jquery code work?

I tried to get the width of an element by its "index":
$(".header__navbar-list__link").on("click", function() {
let index = $(".header__navbar-list__link").index(this);
console .log($(".header__navbar-list__link").get(index).width());
});
And output this width to the console.
However, an error occurs in the console:

Uncaught TypeError: $(...).get(...).width is not a function
    at HTMLLIElement.<anonymous> (home.js:19)
    at HTMLLIElement.dispatch (jquery.min.js:2)
    at HTMLLIElement.v.handle (jquery.min.js:2)

Tried changing .get to [index] - no use
How to make it work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2020-04-23
@duboloms

https://api.jquery.com/eq/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question