Target elements via strings found outside their tag

by timmah

JavaScript

// Search for elements prefixed by a string *outside* of the element
// Change $suspects and $target to match the desired elements you want to get

var $suspects = $('sup'),
	$target = '.<sup><a href',
	counter = 0;

$suspects.each(function() {
	var $this = $(this),
		$text = $(this).parent()[0].outerHTML;
	
	if ($text.indexOf($target) !== -1) {
		// console.log($text + ' found');
		counter++
		
		// Do stuff to the matching elements here
		// In this case, add an easy-to-target unique string for Find and Replace actions later
		$(this).before('@#$').after('.');
		
		// Log the number of results altered
		console.log(counter + ' result found');
		
	} else {
	
		// Do stuff to the non-matching elements here
		// console.log($text + ' does not match');
	}
});