Can css affect elements added by document.write?
If I have this css
div.myContainer img.noCampaign { display:none; }
and this html / javascript
<div class="myContainer">
<script>document.write('<img class="noCampaign" src="whatever.jpg" />');</script>
</div>
I can't get the img element to disappear?
Is there no way to access the img element via css when dynamically adding elements with javascript document.write?
/ T
+2
source to share
4 answers
The CSS styles create js-generated HTML elements - in fact, your example code works exactly as expected in my tests. (After adding to the element <script>
, anyway)
I suspect there is another problem in your code that prevents it from behaving the way you like. If you edit the question with the code you actually used, we can help you find the problem. It's probably just a syntax or a priority error in there.
+3
source to share