Uncaught TypeError: callback.apply is not a function

I looked through the Internet, but could not find the answer to this question, where did this error come from?

Im working on a really simple code where I just replace some text with another.

This is HTML

<div class="imgLittle" style="background-image:url(http://voyagesarabais.com/1874431.jpg4fre);"</div>
<div class="imgLittle" style="background-image:url(http://voyagesarabais.com/159431.jpg4fre);"</div>

This is jQuery

$(document).each('.imgLittle',function(){
  newLink =  $(this).css('background-image').replace(/^(.*?\.jpg).*/, "$1");
  $(this).css('background-image',newLink)
})

But when I run it, it exits with this output:

Uncaught TypeError: callback.apply is not a function

You can look there: JsFiddle .

+4
source share
1 answer

The .eachfirst argument should be a function like this

$('.imgLittle').each(function() {
  // your code
})

Example

+8
source

Source: https://habr.com/ru/post/1614152/


All Articles