当有其他元素时,如何在p标签内换行文本



是否有一种方法,也许使用jQuery,我可以在

标签内包装文本,当有其他元素也在其中?

例如html:

<p class="form-field form-field-wide wc_bookings_field_persons_71">
<label for="wc_bookings_field_persons_71">Children:</label>
<input type="number" value="1" step="1" min="1" max="150" name="wc_bookings_field_persons_71" id="wc_bookings_field_persons_71"> 
Enter the number of Children coming to Soft Play
</p>

但是,我想对文本进行换行,这样我就可以隐藏它并为它创建一个工具提示

你可以使用Jquery .contents()

下面是一个例子:

$(".wc_bookings_field_persons_71")
.contents()
.filter(function () {
return this.nodeType === 3;
})
.each(function () {
$(this).wrap('<a href id="added_a_tag"></a>');
});

最新更新