Chain Trap Chain Trap - 1 year ago 79
Javascript Question

javascript - Append multiple elements to the <input> tag when focused using jQuery

I came to this tutorial site for their awesome Material Design input boxes. The implementation was very easy, but I just don't like the idea of including two

elements (please do check the code to know what I'm talkin' about) so instead I like to append those two elements to the
tag when it is focused with the use of jQuery's
method. But as a newbie to the jQuery world, coding it myself was difficult so I will be needing some help here.

The following example code (below) is what I currently have but they don't work for me.

$("input").focus(function() {
var $elem = '<span class="firstClass"></span>' + '<span class="secondClass"></span>';

Any help?


Answer Source

If you read your link and the html they are not appending a span in an input which is not possible because input cannot contain children elements in html. You might mean to append to the parent of the input though and that would be simpler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download