Home > Enterprise >  how do you add inline styles in jquery?
how do you add inline styles in jquery?

Time:07-21

Hi so this what I have in jquery however it doesn't seem to work, am I missing something?

 modalClose.on("click", () => {
        modalContainer.removeClass("modal-open");
        modalContainer.attr("style", "display:none");
    });

CodePudding user response:

You use the css function, passing it an object with the properties, you use camel case rather than hyphens.

modalClose.on("click", () => {
        modalContainer.removeClass("modal-open");
        modalContainer.css({display: 'none'});
});

//Use camel case for properties with hyphens. style="display: none; background-color: #FFFFFF"
jQuery('.youritem').css({display: 'none', backgroundColor: '#FFFFFF'})

To remove a property from your html send an empty string to the property, the following removes both the display and background-color properties.

jQuery('.youritem').css({display: '', backgroundColor: ''})

  • Related