Skip to content

Instantly share code, notes, and snippets.

@ColinMichaels
Last active July 12, 2019 18:19
Show Gist options
  • Save ColinMichaels/fab130e59b5feb0a73c33fa60cae1246 to your computer and use it in GitHub Desktop.
Save ColinMichaels/fab130e59b5feb0a73c33fa60cae1246 to your computer and use it in GitHub Desktop.
SEO Title and Alt Tags - jQuery
(function ($) {
function getFileName(path, type) {
var file = path.match(/[-_\w]+[.][\w]+$/i);
return (Array.isArray(file))? file[0] : type;
}
function jsUcfirst(string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
$("a").each(function(){
var a = $(this);
var title = (a.attr("href"))? a.attr("href").split("/") : "link";
if(Array.isArray(title))
title = (title.pop() !== "" || title.pop !== undefined )? title.pop(): title[title.length -1];
title = jsUcfirst((title !== undefined)? title : "link");
if(!a.attr("title") || a.attr("title") === "")
a.attr("title", title);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment