jQuery.css() - marginLeft vs. margin-left?

前端 未结 6 1900
感动是毒
感动是毒 2020-12-02 22:22

With jQuery.css() I\'ve been told I can use the following two functions for the same results:

$(\".element\").css(\"marginLeft\") = \"200px\";

$(\".element\         


        
6条回答
  •  温柔的废话
    2020-12-02 23:06

    Late to answer, but no-one has specified that css property with dash won't work in object declaration in jquery:

    .css({margin-left:'200px'});//won't work
    .css({marginLeft:'200px'});//works
    

    So, do not forget to use quotes if you prefer to use dash style property in jquery code.

    .css({'margin-left':'200px'});//works
    

提交回复
热议问题