This question already has an answer here:
Sample Source:
<div>
<br />
<a name="IDATLQHE"></a>
<h2 class="subhead" xmlns="">
<div class="dummy">
<div class="dummyy">
<span>abcd</span>
</div>
<div class="dummyyy">
<span>
<a title="google" href="http://google.com">google.com</a>
</span>
</div>
</div>
</h2>
</div>
Output needed:
I want to replace the contents of the <a>
element in the <div class="dummyyy">
element with the contents of the <div class="dummyy">
element.
JavaScript written:
<script type="text/javascript">
var divs = document.getElementsByClassName('dummy');
for(var i = 0, len = divs.length; i < len; i++)
{
var div = divs[i],
h2 = div.getElementsByClassName('dummyyy'),
h3 = div.getElementsByClassName('dummyy');
if(h2.length === 1)
{
var aa= h2[0],
aaa=aa.getElementsByTagName('a');
if(h2.length === 1 && h3.length === 1)
{
aaa[0].innerHTML = h3[0].innerHTML;
h3[0].innerHTML=null;
}
}
}
This script is working fine in Firefox, but not in IE.
Error at:
getElementsByClassName
aaa=aa.getElementsByTagName('a')
Can any one help on this.
Thanks
getElementsByClassName
is not supported by IE8. If you don't require IE7 support, you can replace it withdiv.querySelectorAll(".dummyy")
getElementsByClassName()
is implemented by all current browsers except IE8 and earlier. IE8 does supportquerySelectorAll()