'each() and resize() in jQuery
Below is the code I wrote.
let thumbHeight =
$('.content').each(function () {
let thumbWidth = $(this).width();
$(this).height(thumbWidth * 0.666)
});
thumbHeight;
$(window).on('resize', thumbHeight);
But it doesn't work when resizing the window. There's only an error message. What should I do?
Uncaught TypeError: ((S.event.special[o.origType] || {}).handle || o.handler).apply is not a function
at dispatch (jquery-3.6.0.min.js:2:43064)
at v.handle (jquery-3.6.0.min.js:2:41048)
Solution 1:[1]
I solved it with the help of two people : @MarkBaijens, @yainspan
let thumbHeight = function () {
$('.content').each(function () {
let thumbWidth = $(this).width();
$(this).height(thumbWidth * 0.666)
});
}
thumbHeight();
$(window).resize(thumbHeight);
Thanks a lot!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kim Da Eun |
