Change CSS properties on click

后端 未结 8 2345
情话喂你
情话喂你 2020-11-29 22:53

I am trying to change the CSS of one element on click of another element. I\'ve searched a lot but nothing works perfectly. Currently I am using the below code, but it doesn

8条回答
  •  死守一世寂寞
    2020-11-29 23:51

    With jquery you can do it like:

    $('img').click(function(){
        $('#foo').css('background-color', 'red').css('color', 'white');
    });
    

    this applies for all img tags you should set an id attribute for it like image and then:

    $('#image').click(function(){
        $('#foo').css('background-color', 'red').css('color', 'white');
    });
    

提交回复
热议问题