javascript - addClass() based on the presence of another class? -
I am working on an ecommerce store product page and an "in-stock" graphic and an "out-of- Stock "There are some limitations in the graphic platform but there is a setting to show the stock graphic, but there is no one in the stock
What I want to do, this page has a stock graphic on the hardcode by default . Like this:
& lt; Div class = "instock" & gt; & Lt; / Div & gt; Below CSS:
.inStock {width: 143px; Height: 40px; Background: URL ('../ product_images / uploaded_images / in-stock .jpg'); Margin-left: 60%; Margin-Top: 5%; Status: Completed; } When a product exits from the stock, the platform backend automatically adds the page that appears in that page:
& Lt; Div class = "currentlySoldOut" & gt; & Lt; P & gt; & Lt; Span lang = "en" & gt; Sorry, but this item is currently unavailable. & Lt; / Span & gt; & Lt; / P & gt; & Lt; / Div & gt; Line When the class "Currently Soldaut" appears, which is automatically generated from the platform, then I want to override the current hardcode "Stock in Stock" graphic, which is the background Edit happens through. Something like this:
Background: url ('../ product_images / uploaded_action / out-of-stock .jpg'); In short, is there a way to override a CSS class on the basis of the presence of another class like "If" is currently showing the Solodete class, then add it to another category. (Where I will control the graphic.)
If you only need it then the page loads initially , You can change that square if there is any element with the selector Is. Currently exists like this: if ($ ('. Currently Soldaut') Length & gt; {} ($ ('. InStock'). RemoveClass ('InStock' ). AddClass ('outOfStock');} Then you need to add style / image-ur to the outOfStock class in your CSS . If your page is being updated, when the user is already viewing, it will be a bit more involved. You can listen to changes in the DOM, and then call the code aboveThis is something like Chrome and Firefox:
function update installs () {// if the above code above ($ ('. Currently Soldaut'). Length> 0 ($ 'InStock'). RemoveClass ('InStock') AddClass ('outO fStock');}} Listen to the Dom updates, Call the function $ ('body') Bind (' DOMSubtreeModified ', function () {updateInStockStatus ();}); Since you probably want to support IE;) To check from time to time that the situation has changed , With setInterval Can abuse are window .setInterval (updateInStockStatus, 5000); This will check every 5 seconds, because the delay is in MS.
Comments
Post a Comment