I need to wrap first and last string that represent title and price of a product of a div with a span tag. This strings are taken from database and varies between products.
I trying to using wrap method on element but nothing change.
Is there any way to solve this issue.
HTML
<div class="product_desc">
Some Bracelet title
<p><span class=""> Material:</span> <span class=""> 926 Silver</span></p>
<p><span class=""> Chain length:</span> <span class=""> 21 cm</span></p>
<p><span class=""></span></p>
Price: €85.37
</div>
jQuery (to wrap first element)
Return the title for example
$(".product_desc").text().trim().split('n')[0])
Wrap not work
$($(".product_desc").text().trim().split('n')[0]).wrap("<span class='hello'></span>")
3
Answers
I think you would need to wrap the textNode rather than just the text:
If you want to wrap both the first and last string, then remove the
.eq(0)
Update per comment:
Please check below code:
I have merge title and price.
Please check and let me know if you find any issues.