Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created January 29, 2018 17:50
Show Gist options
  • Save Garconis/9e90d99f45b8c324655ddf5fa8762023 to your computer and use it in GitHub Desktop.
Save Garconis/9e90d99f45b8c324655ddf5fa8762023 to your computer and use it in GitHub Desktop.
Find text of an element and change it to an anchor, while checking if it has HTTP or HTTPS protocol
(function($) {
$( ".website .sb_mod_acf_single_item" ).text(function () {
if ( ($(this).text().length >=5) && ($(this).text().substr(0, 5) != 'http:') && ($(this).text().substr(0, 5) != 'https') ) {
$(this).replaceWith( '<a href="http://' + $(this).text() + '" target="_blank">' + $(this).text() + '</a>' );
}
else {
$(this).replaceWith( '<a href="' + $(this).text() + '" target="_blank">' + $(this).text() + '</a>' );
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment