css - How do I get the ID of a JQuery item mid-function? -


I am trying to change the background image of some menu options dynamically, when the user clicks on net / click on the menu item To do this, I am using the JQuery .css () method to change the background image. When the user clicks on the menu item, then I'm changing the background image for all menu items in all the original menus, and then one is modified by clicking. How can I do this with JQuery? (Image files are all saved in the same way as "Picture / Library / Nuvar shortcuts / Menu etamid.gif" and "/ Picture Library / Navalbar shortcuts / menu item id 'active. Gif") The situation should reflect. Since I dynamically assign the default background image when I use them in PHP, I do not believe that I want to specify the background images due to a lack of CSS for non-active classes, multi-category CSS I can use Although I may be wrong

what do I have:

  $ ('menuItem'). CSS ("background-image", "url (../picture library / navbar shortcut / productive gif)"); $ ('Menu item active'). CSS ("background-image", "URL (../Picture Library / Novature Shortcut / ProductiveActive. Gif)");   

I have several menu items that are dynamically generated from the database with different IDs. IE

  & lt; Div class = "menuItem" id = "product1" & gt; // I need to change these background images dynamically I & lt; / Div & gt; & Lt; Div class = "menuItem" id = "product2" & gt; // I need to change these background images dynamically I & lt; / Div & gt; & Lt; Div class = "menuItem" id = "product3" & gt; // I need to change these background images dynamically I & lt; / Div & gt; & Lt; Div class = "menuItem" id = "product4" & gt; // I need to change these background images dynamically I & lt; / Div & gt;    

Maybe:

  $ (document) ready (Function ($ ('. MenuItem'). (Function (i) {$ (this). CSS ("background-image", "url (../picture library / navbar shortcut /" + this.id + ".gif)");}) Click $ ('menuItem') (function () {$ (this) .siblings (). Filter ("Active") .removeClass ("Active") .each ( Function (i) {$ (this). Css ("background-image", "url (../picture library / navbar shortcut /" + this.id + ".gif)");}); $ (this) AddClass ("Active"). CSS ("Background-Image", "Uua L. (../Picture Library / Novar Shortcut / "+ this.id +" Active.gif) ");});});   

This Bella, Firebug or something similar From, to see the style changing (because the image does not exist, so it can not be loaded):

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -