Selector and jQuery issues [closed]

0

I am trying to run a code but it does not work, I do not know if it is due to logic error in its execution, see, this code is executed when the OK button is pressed:

$('HTMLNEW').appendTo($(this).closest('.BOX').find('.DIVNEW')).css({
    animation: "---"
});

HTML:

<div class="BOX">
    <div class="DIVNEW">

    </div>    
    <button id="ok">OK</button>
</div>

but it does not execute what is requested, in fact, it does not execute anything.

    
asked by anonymous 30.05.2016 / 09:13

1 answer

2

Use the append function to insert the html into the desired element and use the prev to select the element before your button.

  

Note that append will always add content at the end of   element, not replacing what already exists, if you want to replace   that already exste use the function html , if you want to add at the beginning, use   the prepend .

$('#ok').on('click', function () {
  var html = '<h1>Texto adicionado com append</h1>';
  
  $(this).prev('.divNew')
    .append(html)
    .css('color', 'red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="box">
  <div class="divNew">
  </div>
  <button id="ok">OK</button>
</div>
    
30.05.2016 / 16:32