Consider this element:
Count Dracula: Bleh bleh bleh
I need to split the text in a way that the bit before (and including) the colon has one style (say, bold and red) and the rest has another (say, black and italics).
I am trying to do this using JQuery and here's my attempt:
$("vi").each(function(){
var temp = $(this).text();
temp = temp.split(':');
temp[0] = "<strong>" + temp[0].trim() + "</strong>";
temp[1] = "<em>" + temp[1].trim() + "</em>";
temp = temp.join("");
$(this).text(temp);
});
vi {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<html>
<body>
<vi>Dracula: bleh bleh bleh</vi>
</body>
</html>
Any idea why this wouldn't work? When I try running it, it just outputs the text along with the tags I added as is, i.e. it displays "" instead of applying it, and so on.