How to insert element into another created dynamically

1

When I load the page, I have some checkboxes:

<input type="checkbox">

And when I get to the ready page, I want to put the checkbox inside a label with class 'checkboxPersonalizada', being as follows:

<label class="checkboxPersonalizada">
     <input type="checkbox">
     <i></i>
</label>
    
asked by anonymous 12.01.2017 / 01:49

2 answers

0

I believe you can use the jquery wrap to achieve what you want in the following way.

$(document).ready(function(){
  var checkboxElment = $('#checkboxWrapped');
  var wrapper        = $('<label/>').addClass('checkboxPersonalizada').text();
  var extraElem      = $('<i/>').text();

  checkboxElment.wrap( wrapper ).parent().append( extraElem );
});

link: link

I left the text property if you'd like to add something.

    
12.01.2017 / 03:39
0

Your question was not very clear. But would it be something like that?

	$(document).ready(function() {
	  var conteudo = $(".checkboxPersonalizada").html();
	  var check = "<input type='checkbox'>";
	  $(".checkboxPersonalizada").html(conteudo + check)
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><labelclass="checkboxPersonalizada">
  oi
  <i></i>
</label>
    
12.01.2017 / 02:10