There is a document with the text. The text is divided into paragraphs, in paragraphs there are various other tags. It is necessary to find all the tags inside which there are no other tags and mark them, for example, with a dark background when hovering the mouse. How can jquery do such a search?
1 answer
var a = document.getElementsByTagName('*'); for(var i = 0, il = a.length; i < il; ++i){ if(!a[i].childNodes.length){ a[i].onmouseover = function(){ this.className += ' hilite'; }; a[i].onmouseout = function(){ this.className = this.className.replace(' hilite', ''); }; } }
In principle, you can hang events in another way. The second option:
var a = document.getElementsByTagName('*'); for(var i = 0, il = a.length; i < il; ++i){ if(!a[i].childNodes.length){ this.className += ' hilite'; } } css: .hilite:hover{background:#666}
|