What's wrong with my JS code here?
This is code to make each ".user-message" div that's created test if its font-family is "Roboto", and if it is, to change the font size to 40px.
new divs with the ".user-message" tag are created every second. none of them are having their font size changed though when they're created. What's the way to go about this?
10 Replies
that code will run once for the
.user-message
s that exist, and then never again unless you trigger it againah. should I wrap it in a function and make it run everytime one of the divs is created?
also, you're checking if it is exactly
Roboto
, which may or may not be the case
a mutation observerdefinitely is the case
im not familiar. can you link me something on this?
just check on mdn
it has examples too
MDN Web Docs
MutationObserver - Web APIs | MDN
The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.
Okay, tried this, didn't work though, not sure what's wrong
define "didnt work"
this should run that code when a node is added in the parent element
well the font size didnt change haha
yeah, but that can be anything
for example, wrong font name
or how you're adding the file to the html
please, create a codepen/jsfiddle that shows the problem