JS Playground

14.12.08

How to make div clickable

I saw on some websites, that they don't know how to make div's clickable. So here is a simple solution.


function makeClickable(id){
var elm=document.getElementById(id);
if (elm){
var ahref=elm.getElementsByTagName('a');
for (var j=0;j<ahref.length;j++){
var href=ahref[j].href;
elm.onclick=function(){
window.location=href;
return false;
};
}
var every=elm.childNodes;
for (var i=0;i<every.length;i++){
if (document.uniqueID){
every[i].style.cursor='hand';
}
else{
every[i].style.cursor='pointer';
}
}
}
}
window.onload=function init(){
makeClickable('yourId'); //edit here
makeClickable('anotherId'); //another id here
};


This script will find id in div and make parent div clickable. That is all.

Russian transcriptor

It is already long time from last post. So just quick post. I have made a bookmarklet based on Martin Žantovský Transkriptor founded on web. It is not online already so here is a my bookmarklet version of that script. It is very helpfully on russian forums. In new blogger it seems impossible to add bookmarklet, so you will find it here Transcriptor