Friday 11 March 2016

jquery - How do you set a css class attribute with Javascript?




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");


And



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






CSS:



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

display: none;
background-repeat:no-repeat;
}


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');

Answer



Use the style property to set the style in javascript.



LoadingImg.style.display = "block";

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...