There is such a code:

$(document).ready(function(){ $('.update-plugins').each(function(){ if ($(this).data('url')) { $.get( $(this).data('url'), function( data ) { $(this).children('.plugin-count').text(data); }); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <span style="background: green;" class="update-plugins count-2" data-url="/getQMails/index.php" title="Писем в очереди на отправку..."><span class="plugin-count"></span></span> 

It does not work, although at the address /getQMails/index.php in an AJAX request, the desired value is /getQMails/index.php , somewhere messed up in the line:

 $(this).children('.plugin-count').text(data); 
  • this inside callback get this is not an element - Grundy

2 answers 2

 $(document).ready(function(){ $('.update-plugins').each(function(){ var $oldThis = $(this); if ($(this).data('url')) { $.get( $(this).data('url'), function( data ) { $oldThis.children('.plugin-count').text(data); }); } }); }); 

You have $ (this) pointed to an AJAX object.

  • tried the result the same does not change - Enshtein
  • Thanks for the decision! - Enshtein
  • one
    updated the answer, another mistake - Maks Devda
  • one
    Close the question. You 're welcome - Maks Devda

this inside the get callback is not an html element.
Save it before use.

 $('.update-plugins').each(function(){ var $this = $(this); if ($this.data('url')) { $.get( $this.data('url'), function( data ) { $this.children('.plugin-count').text(data); }); } });