How to change the innerHTML of a DIV, since there are other elements within it that cannot be changed?

Asked

Viewed 5,306 times

1

I have a blog and the attribution of this blog is incorrect and not even changing it works. I wanted to use a script that changes innerHTML within this DIV but without changing other content.

Example:

function setAttrib(nameof, content){
document.getElementById(nameof).innerHTML=content;
}

But the problem is that within this DIV there are other items within it that I cannot change and the only item I want to change would be another DIV without ID but has Classname, but as it is a Blog has several Classname of the same type.

Observe:

HTML SOUCE CODE VIEW

Note that in the image the Attribution1 ID is the item I want to change but has other items within this DIV.

  • yes the position of the element is fixed!

1 answer

4


If the internal element is with the class widget-content, do so:

document.querySelector('#Attribution1 .widget-content').innerHTML = 'sei lá';
  • is yes. but you need jQuery or another lib to run this script?

  • 4

    No, this is pure Javascript (which works even on IE8).

  • ok I will test this script and I will evaluate your response.

  • worked properly! thanks for the help!

  • 1

    Nice, nice of you to help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.