1.10. get,set - css

 


Demo : https://www.lenlop123.com/2020/09/110-getset-css.html


<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>

<p id="p_1" style="background-color:#ff0000">This is a paragraph.</p>
<p id="p_2" style="background-color:#00ff00">This is a paragraph.</p>
<p id="p_3" style="background-color:#0000ff">This is a paragraph.</p>

<input id="but_get_css" type="button" value="get css">
<input id="but_set_css" type="button" value="set css">

<script>
    $(document).ready(function(){
     
      // get css  
      $("#but_get_css").click(function(){
        alert("Background color = " + $("#p_1").css("background-color"));
      });

      // set css  
      $("#but_set_css").click(function(){
        $("#p_1").css("background-color", "yellow");
        $("#p_2").css({"background-color": "violet", "font-size": "200%"});
      });


    });
</script>


Nhận xét