How do you set a css class attribute with Javascript? [duplicate]

Tags: javascript,jquery,html,css

Problem :

This question already has an answer here:

The element i'm working with is a image i would like displayed during load time.

I am trying to set a css class attribute, i can set attributes on my image but its class attributes override's it.

So i need to set the class attribute. The class is .bgImage

This is how i set the attribute:

LoadingImg.setAttribute("display", "block");

This is what i have tried:

LoadingImg.className("display", "block");


LoadingImg.setAttribute(".bgImage display", "block");


.bgImage {
  position: fixed;
  top: 0; left: 33%;
  right: 0; bottom: 0;
  z-index: 1;
  display: none;

Exstra info:

LoadingImg is the image object, i had to grab it through iFrame levels.

var HomeDoc = $('#ContentFrame').contents()[0];
var LoadingImg = HomeDoc.all.namedItem('LoadingImg');

Solution :

Use the style property to set the style in javascript. = "block";

    CSS Howto..

    how to change color of selected menu in css or jquery [closed]

    How to draw diagonal lines with css [duplicate]

    How to set an html element's height as { 100% - 10em from bottom }

    How to combine jquery codes with similar functions?

    How to include SASS into CSS

    Japanese Text not showing correctly

    How to add JS and CSS to all content parts in an Orchard module

    How to make a border colorful using CSS?

    How to use box shadow in css?

    How to block CSS and js file loading in Google Blogger template?

    How to use Grunt while continually compressing css / javascript

    How use horizonal scorll div content div

    How to draw a half circle (border, outline only) [closed]

    How to force resize inside iframe?

    How to make to div comes the one under the other

    How to format HTML/CSS to align with single word in sentence?

    How to draw a specific shape in CSS? [closed]

    How to display an image from a dropdown menu selection?

    How to remove default CSS from TextField in flex?

    How can i auto rotate this carousel

    How to use Jekyll baseurl in css files

    How can I center my ul li list inside my div?

    how to switch to another view using css class on click in angularjs using ngclass

    how to define style for a group of child elements from parent element's style?

    Glide.js, how to check size of image?

    how to desaturate background image of a div using css?

    How to format a title attribute with css (setting more width)?

    Html and CSS for emails, how to, where to?

    How do I pass a background-image url from one div onto another using jQuery?

    JavaScript/CSS: How to resize (scale) window content