Wrap text with an element, based on the text within it

Split the text based on a certain character and then wrap part of it with a new element.

by Jon Fuller

HTML

<div class="et_pb_toggle_title">
	<h4>
		This is My Title - Pretty cool, right?
	</h4>
</div>
<hr>
This grabs any text within the selector (if it contains the - character).<br>
It grabs that character and any text after it and then gets replaced with new text.

CSS

.accordion-title-color {
	color: red;
}

JavaScript

(function($) {
	function accordion_title_tweak() {
		$('.et_pb_toggle_title h4:contains("This is ")').each(function() {
			var $this = $(this),
				splitText = $this.text().split('This is '),
				formattedText = '<span class="accordion-title-color">Services in </span>' + splitText[1];
        	$this.html(formattedText);
		});
	}
	$(document).ready(function() {
		accordion_title_tweak();
	});
})(jQuery);