How to add and remove background images in css on clicking a link on page

Tags: javascript,jquery,css,ajax,onclick

Problem :

Ive that small Fiddle

    <img src="" id="bg" /><br />

    <a href="" title="Switch" class="menulink">DE</a>
<a href="" title="Switch" class="menulink2">EN</a>
<a href="" title="Switch" class="menulink3">FR</a>

$(function() {



It works fine but my problem is:

I need to add an background image to every linkclass for selected/active state and inactive/default state, if i click another link on page.

For example the link "de" has default a white bg-image and if i click the link the bg-image changes to a black image for selected state.

If i click now "en" it will change the "de" link back into inactive state with the white background image and set the "en" bg-image-link into selected state-imagelink and will remove it if another link will be clicked.

I hope someone has an idea :)

Solution :



    }); I did changes on your fiddle, this fiddle could help you.

    CSS Howto..

    Working with a css3 key frame slide effect but cant figure out how to configure correctly.. Fiddle included

    How to select children in CSS

    How to make multiple gradient work with CSS

    CSS: how to align text content horizontally-centered and vertically-centered?

    how do you change the color of nav bar

    How to make a JS horizontal content slide from px to % responsive

    How to change css class for multiple DOM elements with jQuery? [closed]

    How to center a CSS Hexagon

    How to sort and combine this css rules so it doesn't repeat so much?

    Show the menu at the center of the data toggle

    CSS Tooltip has different position in different browsers. How can I account for this?

    How to override height

    html, svg, css how to make mouse event not fire on transparent color

    How to display only the
      that has a selected
    • in it, including all of the
    • s in that parent ul, not just the selected ones?

    How do I get a CSS class to work in my Javascript file?

    HTML - How to put text over a white background over a background image

    Beginner: How to get a fixed element to a left position (float left?) - JSFiddle included

    How to Skew divs with css

    jQuery + CSS: How to scroll smooth, regarding a fixed header?

    How to… Three wordpress sites with one css … ? child theme

    How do I customize an asp:Button class?

    How do I put these on the same line?

    How would you code this: Grid-breaking shapes

    How can I escape string css in sass/scss?

    How to override inline css from external class?

    How read(get) css style value of a server-side div in code behind(not set)?

    Where and how to add/edit css in roots starter theme

    How to hide a class on specific page using css

    How to silently hide “Image not found” icon when src source image is not found

    how to align right hand side image on top of text on mobile screen