Jump to content

How to add icon in the textbox


kasep

Recommended Posts

Hai... 

iam newbie in jquery sintaks

i try to add icon in the  textbox on login.. class textbox is below class form-group row

my script is

var header = '<span class="form-group row"><i class="fa fa-user"></i></span>';
$('[class="input-group-addon"]').prepend(header);

but the result is nothing

can you help me

Thank you

 

 

Untitled.png

Link to comment
Share on other sites

I don't see any elements in your code with a class "input-group-addon". You need to add that element to your HTML for this code to work. Either that, or use a different class name to select the element.

You should use the class selector instead of the attribute selector, otherwise it will only select elements that have exactly that class name and nothing more. The class selector is the same as in CSS:

$('.input-group-addon').prepend(header); 

jQuery is not necessary for this. It can be done with plain Javascript:

var header = '<span class="form-group row"><i class="fa fa-user"></i></span>';
var element = document.querySelector(".input-group-addon");
element.innerHTML = header + element.innerHTML;

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...