Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Created April 20, 2017 03:34
Show Gist options
  • Save gHashTag/e9ccb0b6d95ed3de59e9b037cd419fcd to your computer and use it in GitHub Desktop.
Save gHashTag/e9ccb0b6d95ed3de59e9b037cd419fcd to your computer and use it in GitHub Desktop.
<script>
(function($) {
$.fn.findReplace = function(options) {
var settings = $.extend({
findText: null,
replaceText: "",
customClass: "",
completeCallback: null
}, options);
return this.each(function() {
var StringToFind = settings.findText;
var regExpression = new RegExp(StringToFind, "g");
var replacement = "<span class='" + settings.customClass + "'>" + settings.replaceText + "</span>";
$(this).html(
$(this).html().replace(regExpression, replacement)
);
if ($.isFunction(settings.completeCallback)) {
settings.completeCallback.call(this);
}
});
};
}(jQuery));
$("a").findReplace({
findText: "SEE",
replaceText: "Смотреть",
customClass: "div.healcode .trainer_list .trainer_teaches_link a",
completeCallback: function() {
$('.notification').text('Executed the plugin on all links').fadeOut(5000);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment