Mellon
Mellon

Reputation: 38872

How use jQuery to append a element to the right side of another element?

I have

<input type='text', id='name'></input>

and I have

<p>my name is xyz</p>

I would like the <p> element to be located 20px the right side of <input>, how to use jQuery to achieve this?

Upvotes: 1

Views: 4830

Answers (1)

S L
S L

Reputation: 14318

$('<p></p>').html('my name is xyz').css('margin-left', '20px').insertAfter($('#name'));

or

$('/*select p*/').css({'margin-left':'20px'}).after($('#name'));

Or just put css

p{
  margin-left: 20px;
}

Upvotes: 3

Related Questions