Reputation: 31
Want to change HTML content of a div which has a certain class but problem is there are several others and they get change too.
<div class="x"></div>
<div id="y"><div class"x">Change this</div></div>
<div class="x"></div>
I'm trying
function ReplaceContentInContainer(matchClass,content)
{
var elems = document.getElementsByTagName('*'),i;
for (i in elems)
{
if((" "+elems[i].className+" ").indexOf(" "+matchClass+" ") > -1)
{
elems[i].innerHTML = content;
}
}
}
window.onload = function ()
{
ReplaceContentInContainer("x","Success"}
but as you can guess it changes every class"x", so how can I limit this only to the class="x" which is nested in a div with id="y"?
Upvotes: 0
Views: 132