I'm trying to access the body tag but it seems it's not possible using document.getElementsByTagName(tagName) and $A.util.addClass, I want to add a background image, I was trying to do it in the component's style file but couldn't make it work.

Any ideas or suggestions to follow, please?


You can use the .THIS class in the Lightning Component style file. .THIS refers to the whole lightning component.

Step 1:

Get the url of the static resource that is similar to this format resource/#############/resourceName.

You can get this simply by adding the static resource reference in Lightning Component Markup(Component File) - {!$Resource.imageResourceName} enter image description here

Once you run the component - it will show the URL of the static resource. enter image description here

Step 2:

Just grab the URL that you got in step one and add it in the .THIS class, something like this:

background-image: url('/resource/1556180826000/Arunachala_pic') !important; 

And that's it!

enter image description here

I hope this helps! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.