Uncaught TypeError: $ (...) .appendTo is not a function

0

I have this element:

<p class="info" style="text-align: left;">Encuentra toda la info aquí</p>

And I want to move it to this div ;

<div id="informacion"></div>

I have tried in the following ways:

 $('.info').appendTo('#informacion');
 $('p.info').appendTo('#informacion');

But always the same error comes out.

    
asked by Lina Cortés 12.03.2018 в 16:12
source

1 answer

1

That error comes to you because that function you use is not defined because you need the jQuery library you must add it

Just as you have it, it is already well appendTo (this causes it to be added to the end of the element):

$ (". info"). appendTo ("# information");

Alternatively, you can use the prependTo function (add it to the beginning of the element if you have more elements within it ):

$ (". info"). prependTo ("# information");

Example:

 
 $("#appendTo").click(function() {
 $('.info').appendTo('#informacion');
 });
 
.info {
  border: 1px solid red;
   min-height: 50px; 
}
#informacion {
  border: 2px solid blue;
  min-height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<p class="info" style="text-align: left;">Encuentra toda la info aquí</p>

<div id="informacion">
<h3>Div informacion</h3>

</div>

<button id="appendTo">Mover a #informacion</button>
    
answered by 12.03.2018 / 16:49
source