﻿/*
Adds an attribute to every element whose tag name is "a"  
by using an attributes collection.
I use a DOM to finish  this function
*/
function SetTargetBlank(ID)
{
    //Get a element collection by tag name "a"
    var href=document.getElementById(ID).getElementsByTagName("a");
    //Make every element hava a new attribute "target" that value is "_blank"
    for(var i=0;i<href.length;i++)
    {
        //Creat a new attribute
        var target=document.createAttribute("target");
        //Set the attribute value "_bank"
        target.value="_blank";
        //Get attributes of every element
        var  attributes=href.item(i).attributes;
        //Adds the attribute "target" to every element
        attributes.setNamedItem(target);
    }
}
