jQuery: Apply css to image on click event

Posted by DasRakel on Stack Overflow See other posts from Stack Overflow or by DasRakel
Published on 2010-05-27T09:26:37Z Indexed on 2010/05/27 9:31 UTC
Read the original article Hit count: 173

Filed under:
|
|

I want basically the same as http://stackoverflow.com/questions/530701/jquery-select-image

a row of images that you can select one of.

But I'm trying to style the one I select, and store it.

var selectedicon = "";

function selecticon(){

$('#iconselect').children().click(function(){
        $(".selectedicon").removeclass("selectedicon");
        selectedicon = $(this).attr("src");
        $(this).addclass("selectedicon");
    });
}

on this

  <div id="iconselect">
    <img src="/red-dot.png" class="selectedicon" />
    <img src="/green-dot.png" />
    <img src="/blue-dot.png" />
    <img src="/orange-dot.png" />
</div>

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about css