0

Please refer - https://jsfiddle.net/QLfxs/142/

$("#z").clone().appendTo($("#x"));

A button is cloned. This cloned button is appended inside the text box. The appended button is not visible. Why? and how to get it visible? The input box is acting like a black hole!

anand patil
  • 507
  • 1
  • 9
  • 26

4 Answers4

1
<input val='xx'> 
<button> button </button>
</input>

Is equivalent to

<input val='xx'></input>
<button> button </button>

The closing input tag </input> is ignored. So when you try and append a button to within the <input> element, it won't appear.

Here is a link to a JSFiddle.

Read more here.

Sinan Guclu
  • 1,075
  • 6
  • 16
0

You are appending the clone button inside the input DOM, which is incorrect.

<input type="text" id="x"/>
<div id="n"></div>
<button id="y"> somesome
</button>

in JS append to the div

 $("#y").clone().appendTo($("#n"));

Do it like this

Cyril Cherian
  • 32,177
  • 7
  • 46
  • 55
0

You can't append element to an input element instead, append next to the element using after() method.

$(document).ready(function() {
  $("#x").after($("#y").clone());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="x"/>
<button id="y">somesome
</button>

or use insertAfter() method.

$(document).ready(function() {
  $("#y").clone().insertAfter('#x');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="x" />
<button id="y">somesome
</button>

Refer : What is innerHTML on input elements?

Community
  • 1
  • 1
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0

You cannot append anything to the input element, It will be better if you use .after or .before in jquery. So, your solution will be :

$("#x").after($("#y").clone())

$(document).ready(function () {
   $("#x").after($("#y").clone())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="x">
<button id="y"> somesome
</button>
bhansa
  • 7,282
  • 3
  • 30
  • 55