Posts Tagged ‘jQuery’

มาเรียนรู้ if else ใน jQuery ส่วนของ Css กัน

รู้มัยครับ เราสามารถ เขียน if else แบบย่อในการ add stylesheet ให้กับ jQuery ได้ด้วย แถมการเขียนก็เข้าใจง่ายๆ นิดเดียวเอง โดยตัวอย่างที่จะแสดงให้ดูวันนี้ เป็นการ ใช้ if else อย่างย่อ กับ การทำงานในส่วนของ css เป็นยังไง มาลองดูกัน…

$(document).ready(function() {

  $(‘div#tee’).click(function() {

    var bgc = $(this).css(‘backgroundColor’);

    $(this).css({backgroundColor: bgc == ‘#ffcccc’ || bgc == ‘rgb(255, 204, 204)’ ? ‘#ccccff’ : ‘#ffcccc’});

  });

});

Read the rest of this entry »