How to append span to select control?

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!

appendTo means that you are moving the left element to the end of the right element.
In this case, that means you are moving the existing HTML label, to the end of the $label that you defined in the JavaScript code.

That doesn’t seem to be what you intend to occur.

Instead, using append moves the HTML element from the right, to the end of the HTML element to the left.
You might want to try using append instead of appendTo

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.