click function, css add class only on this item

最后都变了- 提交于 2019-12-25 08:09:46

问题


I have a grid with an image being grey, on hover the image get colorize (the image can not be setup as background image for information).

When Hover the image, a text appear, on click on this, I have a content which toggle.

Here are my two issues:

1 On toggle, only the image of the item have click should be colorize, actually they all get colorize unfortunatly. ( test on the first item of the secodn row)

I tried to use $(this).prev without success.

( see the code)

//** HERE THE TOGGLE FUNCTION **/

$('#toggle').click(function() {
$('.toggle').slideToggle('fast');
return false;
});

$('#toggle').click(function() {

$('.toggleaction').addClass('current');

       if($('.toggleaction').toggleClass('current')){

     $('.hide').toggleClass('displayon');
     $('img.grayscale').css('-webkit-filter', 'grayscale(0%)');


}


});

--EDIT:

got it by replacing:

$('#toggle').click(function() {
 $('.toggle').slideToggle('fast');
 return false;
 });

 $('#toggle').click(function() {

 $('.toggleaction').addClass('current');

       if($('.toggleaction').hasClass('current')){

     $('.hide').addClass('displayon');
 $('img.grayscale.oui').toggleClass('color');

 }

 });

2/ If I add more toggle section, on click of one, none of them appear . ..

Any help will be incredible !!!! If you have any suggestions, please let me know :)

To see the full code live:

http://codepen.io/anon/pen/KNRBQX

---EDIT

I got the 1/ working fine, see updated codepen

来源:https://stackoverflow.com/questions/41018941/click-function-css-add-class-only-on-this-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!