How do you alter the content of a <div>
using javascript when the <div>
has no id
or class
.
I know that using something like document.getElementById('foo').innerHTML = 'Your content';
Could have been used if the <div>
had an id. But in my case the content I want to alter is like this
<div unselectable="on" style="position: absolute; padding: 2px; top: 0px; left: 1px; background-color: rgb(255, 102, 0); color: white;">BOO</div>
I am partial to using document.getElementsByTagName("div")[0].innerHTML = "BOO";
to find it but how do I then proceed to modify its content? Also is this a good way to doing things?
No there are other div too but that is the only one with that content Boo
If that case, you can find by :contains
$("div:contains('BOO')").html('hello');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With