Created
January 29, 2018 17:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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