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
You can use insertBefore
$('<span class="tag">sd<button class="close" type="button">×</button></span>')
.insertBefore('#form-field-tags');
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>');
使用.prepend()
:
$('div.tags').prepend('<span class="tag">sd<button class="close" type="button">×</button></span>')
尝试:
$('input.tags').prepend('<span>what you want</span>');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.