简体   繁体   中英

how do you add inline styles in jquery?

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

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: ''})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM