Image HTML looks like this
<img src="image.png" alt="Alt text" title="Description">
I have special function to output display Image title as filename with no extension and Description within fancybox.
My question is: how to get value from alt attribute and output it instead of filename(title_new) if alt is not empty.
jquery.fancybox-1.3.4.pack.js (full http://pastebin.com/bFmg95AT)
_format_title = function(title) {
var nstr=imgPreloader.src;
var nres=nstr.split("/");
var img_name=nres[nres.length-1];
var img_name_arr=img_name.split(".");
var title_new= "<b>"+img_name_arr[0]+"</b><br>";
if (title && title.length) {
if (currentOpts.titlePosition == 'float') {
return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' +title_new+ title+ '</td><td id="fancybox-title-float-right"></td></tr></table>';
}
return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title_new + title + '</div>';
}
To get the alt attribute of an image you would use code like this where 'this' is the image you are using.