Image Caption
Showing posts with label javascript replace ID. Show all posts
Showing posts with label javascript replace ID. Show all posts

Saturday, November 24, 2012

JavaScript using onload replace ID, Class and Attributes


//Must replace the red colored text 

<script type="text/javascript">
function replaceSrc()
{

    var a= document.getElementsByTagName('TagName');

    for(var i = 0; i < a.length; i++)
    {
        var link= a[i];

        if(link.AttributesName == 'SearchValue')
        {
            link.AttributesName= 'ReplaceValue';
        }
    }
}

window.onload = replaceSrc();
</script>

//Demo code for Replace <a> Title attribute.


<script type="text/javascript">
function replaceSrc()
{

    var a= document.getElementsByTagName('a');

    for(var i = 0; i < a.length; i++)
    {
        var link= a[i];

        if(link.title == 'Publish')
        {
            link.title = 'Active';
        }
    }
}

window.onload = replaceSrc();
</script>