certainlyakey
6/23/2014 - 1:08 PM

Wrap text fragment before a symbol in HTML element (jQuery)

Wrap text fragment before a symbol in HTML element (jQuery)

//Config
var selector = ''; //selector to search (string, for example '.front_recentnews h1')
var delimiters = [ ":" ]; //, "." //an array of delimiters

$.each(delimiters, function() {
	var delimiter = this;
	var text = '';
	var befDel = '';
	var aftDel = '';
	var headings = $(selector+":contains('"+delimiter+"')");
	$.each(headings, function(i, val) {
		text = $(this).html();
		befDel = text.split(delimiter)[0];
		aftDel = text.split(delimiter)[1];
		$(this).html('<span>'+befDel+delimiter+'</span>'+aftDel);
	});
});