If you absolutely do not need to choose colors or border sizes dynamically, which I doubt is because you are a recognized beginner, stuffing style sheets with Javascript is a Rube Goldberg device. It seems elegant to be able to do this, but if your application is important to you, you will regret it. (You can use innerHTML to populate the stylesheet in this case - at least it will be faster than calling the DOM.)
Pranay Rana's answer to using getElementsByTagName is the best option if your restrictions are actually stable (only one img). Get the el element reference to gal1 using getElementById, then var myimg = el.getElementsByTagName ("img") and you're almost done.
If you insist on imposing style nodes, you can use any properties you want in the myimg style property. It becomes embedded.
However, you almost certainly don't need to write new rules, and you can often avoid changing the style of the inline style. It is more predictable and stable to change the class attribute on myimg and use a predefined set of style classes for the cases you need to handle. This will give a nice clean separation of style from the script, and avoid both aligning the style rules and embedding the style tree style by injecting code.
source share