Codice PHP:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function lookForImg(id,path){
var el= document.getElementById(id);
if(el){
var img= el.getElementsByTagName('img')[0];
if(img){
var a= document.createElement('a');
a.href= path;
img.style.border= '0px solid #FFFFFF';
a.appendChild(img);
el.appendChild(a);
//bene, qui c'è l'immagine
return true;
}
//qui non c'è l'immagine
return null;
}
//livello non presente
return null;
}
window.onload=function(){
alert(lookForImg('id_livello','mypage.html'));
}
</script>
</head>
<body>
<div id="id_livello">
[img]path.jpg[/img]
</div>
</body>
</html>