Mayank Patel
Mayank Patel

Reputation: 117

How to add span in div using jquery?

I want to add span to div code below to understand my problem

<div class="tags">
**<span class="tag">sd<button class="close" type="button">×</button></span>**
<input type="text" placeholder="Enter tags ..." id="form-field-tags" name="tags" style="display: none;"><input type="text" placeholder="Enter tags ...">
</div> 

**<span>** decribe place for insert one or many tag between div before input tag

Upvotes: 0

Views: 3601

Answers (4)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85653

You can use insertBefore

$('<span class="tag">sd<button class="close" type="button">×</button></span>')
.insertBefore('#form-field-tags');

Upvotes: 1

TheGr8_Nik
TheGr8_Nik

Reputation: 3200

try with:

$('input.tags').prepend('<span>what you want</span>');

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

Use .prepend():

 $('div.tags').prepend('<span class="tag">sd<button class="close" type="button">×</button></span>')

Upvotes: 0

Felix
Felix

Reputation: 38112

You can use .prepend():

Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.

$('div.tags').prepend('<span class="tag">sd<button class="close" type="button">×</button></span>');

Fiddle Demo

Upvotes: 0

Related Questions