Problem with adding span dynamically

Hi all,
In my jQuery v3.3.1 / Bootstrap v4.1.2 application
I need after select input and “entries” text create/update (if it exists ) some label with text. I have select block:

<div class="dataTables_length" id="get-client-dt-listing-table_length"><label>Show
   <select name="get-client-dt-listing-table_length"
           aria-controls="get-client-dt-listing-table" class="">
      <option value="25">25</option>
      <option value="50">50</option>
      <option value="100">100</option>
      <option value="200">200</option>
      <option value="-1">All</option>
   </select> entries</label></div>

On data retrieve in JS code I try to make :
var $label = $("<label>").text( ". Shows "+settings.json.data.length + " of " + settings.json.recordsFiltered + " clients" ) .attr({id: 'span_clients_records_count', name: 'span_clients_records_count'}) ;

$(".dataTables_length > label ").appendTo($label);

I expect new label would be visible after label, but failed and select
input is not visible and in browser console I see that wrapping div is empty.

Which is the valid way?

Thanks!

It’s either should be append (not appendTo) or you should switch ".dataTables_..." and $label.

1 Like