Johnny Mopp Johnny Mopp - 1 year ago 75
jQuery Question

Create input as child of input

Is it possible to create a button that is the child of an text?

<input type="text">
<input type="button" />

The reason I ask is I would like to make a combo box. See this fiddle. Doing this in jquery, the button does not appear. Doing it in regular html, the 2nd input is not a child of the first (in Chrome at least).

I could put a text and button in a span, but I prefer to create the text box like in the example so later the value can be retrieved like: $("#test).val();

PS I know other combo box plugins exist. I would like to roll my own for learning purposes.

Answer Source

This will result in invalid HTML, so its not possible to do this. What you can do is create a div, which is a block element and fill it with a text box + button Inline elements.

With some styling in your CSS you can make your div look like a textbox and your textbox like a div, without borders and bevels. Resulting in something that looks like the thing you are trying to achieve here.

To get rid of the textbox look on your input use #YourTextBox {border: none;}