Change CSS properties on click

后端 未结 8 2287
情话喂你
情话喂你 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:54

    This code seems to work fine (see this jsfiddle). Is your javascript defined before your body? When the browser reads onclick="myFunction()" it has to know what myFunction is.

    0 讨论(0)
  • 2020-11-29 23:55

    In your code you aren't using jquery, so, if you want to use it, yo need something like...

    $('#foo').css({'background-color' : 'red', 'color' : 'white', 'font-size' : '44px'});
    

    http://api.jquery.com/css/

    Other way, if you are not using jquery, you need to do ...

    document.getElementById('foo').style = 'background-color: red; color: white; font-size: 44px';
    
    0 讨论(0)
提交回复
热议问题