jQuery เปลี่ยน class ของ tag หรือ selector ทำงานเหมือน mouseover และ mouseout

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: jQuery เปลี่ยน class ของ tag หรือ selector ทำงานเหมือน mouseover และ mouseout

Re: jQuery เปลี่ยน class ของ tag หรือ selector ทำงานเหมือน mouseover และ mouseout

โดย mindphp » 24/01/2023 2:32 pm

หมวดแชร์ความรู้การใช้ jQuery เพิ่มเติม
viewforum.php?f=78

บทเรียน jQuery
https://www.mindphp.com/บทเรียนออนไลน์/ ... ที่-1.html

jQuery เปลี่ยน class ของ tag หรือ selector ทำงานเหมือน mouseover และ mouseout

โดย mindphp » 24/05/2010 4:42 pm

การเปลี่ยน class ของ css ตาม event ที่เราต้องการนอกจากใช้ javascript เปลี่ยน class css แล้ว เราสามารถใช้ jQuery แทนได้เพื่อเขียนโค้ดสั้นลง และ มีฟังก์ชั่นสำหรับ removeClass, addClass ได้ตามต้องการ

ตัวย่าง jQuery เปลี่ยน class ของ tag หรือ selector ทำงานเหมือน mouseover และ mouseout ของ javascript

โค้ด: เลือกทั้งหมด

    $("div.sidenavOff").mouseover(function(){
    	$(this).removeClass().addClass("sidenavOver");
    }).mouseout(function(){
    	$(this).removeClass().addClass("sidenavOff");		
    });

ข้างบน