admin管理员组

文章数量:1320632

I've looked accross the web but did not find an answer to this question, where does this error could came from ?

Im working on a really simple code where I just replace some text by an other.

This is the HTML

<div class="imgLittle" style="background-image:url(.jpg4fre);"</div>
<div class="imgLittle" style="background-image:url(.jpg4fre);"</div>

This is the jQuery

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

But when I run it it e out with this output :

Uncaught TypeError: callback.apply is not a function

You can have a look there : JsFiddle.

I've looked accross the web but did not find an answer to this question, where does this error could came from ?

Im working on a really simple code where I just replace some text by an other.

This is the HTML

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

This is the jQuery

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

But when I run it it e out with this output :

Uncaught TypeError: callback.apply is not a function

You can have a look there : JsFiddle.

Share Improve this question edited Nov 2, 2015 at 13:59 Baldráni asked Nov 2, 2015 at 13:50 BaldrániBaldráni 5,6388 gold badges56 silver badges82 bronze badges 3
  • 1 .each() wants a function as its first parameter, you're passing a string. See Alexander's answer below for the correct usage. – Paul Roub Commented Nov 2, 2015 at 13:53
  • 1 $(this).css('background-image').replace(/^(.*?\.jpg).*/, "$1"); is not going to do anything FYI. The image url is not going to be updated. – epascarello Commented Nov 2, 2015 at 13:55
  • @epascarello indeed, just change the function thank you all ! – Baldráni Commented Nov 2, 2015 at 13:58
Add a ment  | 

1 Answer 1

Reset to default 8

In .each first argument should be function, like this

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

Example

本文标签: javascriptUncaught TypeError callbackapply is not a functionStack Overflow