|
My requirement is that I want to identify the <img> tags in html page, want to place a border line for images and want to display ALT Text. If there is no ALT attribute, i want to display an image. Following function shows "NOALT" message, in place of "NOALT" I want to display an image. Place the following function in HTML page, add 4 image tags in HTML page and call the bellow function in "onload" attribute of <body> tag.
function showimage()
{
var z=0,
tag=new Array('img');
for(n=0;n<tag.length;n++)
{
t=document.getElementsByTagName(tag[n]);
{
for(i=0;i<t.length;i++)
{
{
var l;
if(t.attributes.alt.specified)
l='alt=\"'+t.alt+'\"';
else
l='<strong style=\"color:red\">NoAlt!</strong>'
}
h=t.outerHTML;
t.outerHTML='<span style=\"color:navy;font:x-small arial;background:#f5deb3;\"><b><'+tag[n]+' '+l+'></b></span> '+h;
t.style.padding='3px',t.style.border='1px solid red';
if(h!='')
z=z+1;
}
}
}
if(z==0)
alert('No Images');
}
|
|
|
|
|
|
|
|