I want to add first word in one tag and remaining text in another tag separated with
between them. Basically I want this type of html structure.
<div class="hotspot-name">
<span>Building</span>
<br/>
<span>One text text</span>
</div>
Whatever I have tried mentioned in below snippet.
$(".hotspot-name span").each(function () {
var html = $(this).html().split(" ");
html = html.slice(0, -1).join(" ") + " <br />" + html.pop();
$(this).html(html);
});
.hotspot-name{margin-top:10px;}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div class="hotspot-name">
<span>Building One</span>
</div>
<div class="hotspot-name">
<span>Building Two test test</span>
</div>
<div class="hotspot-name">
<span>Building Three test test</span>
</div>
<div class="hotspot-name">
<span>Building Four</span>
</div>
Thanks!!