You can also list all the HTML Elements inside a DIV with specific attributes. The following coding will output list of a tags inside the div2.
Code:
function getElementsByAttr(attr, value, parent)
{
var collection = parent.getElementsByTagName('#'),
list = [];
for (var i = 0, len = collection.length, curr; i < len; i++)
{
curr = collection[i];
if (typeof curr[attr] != 'unknown' && curr[attr] === value)
{
list.push(curr);
}
}
return list;
}
window.onload = function(){
var list = getElementsByAttr('tata', 'tab3', document.getElementById
('div2'));
Bookmarks