Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > jQuery > jQuery Introduction > jQuery Css : jQuery and Css



Clound SSD Virtual Server

jQuery Css : jQuery and Css

jQuery Css รูปแบบคำสั่งการใช้ jQuery กับ Css บน jQuery Library Framework
jQuery กับ Css อีกหนึ่งความสามารถของ jQuery ก็คือการจัดการ Css หรือกำหนดคุณสมบัติ ของ element ได้แบบง่าย ๆ เช่นเดียวกัน โดยผ่าน Syntax ง่าย ๆ เช่น

jQuery Css Syntax
$("selector").css("value");



1. ตัวอย่างการใช้ property ของ css()

Code (jQuery)
<html>
<head>
<title>ThaiCreate.Com jQuery Tutorials</title>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	$("body").css("background-color","yellow");

	$("p").css("background-color",$("#div1").css("background-color"));

	$("#btn1").click(function(){
		$("body").css("background-color","pink");
		$("#div1").css("background-color","green")
		$("#div2").append($("body").css("background-color"))
		$("#div3").css({"font-size:":"10px","color":"gray","padding":"5px 0px 5px 10px"});

		$("#txt1").height("30px");
		$("#txt1").width("100px");
	});

});
</script>
</head>
<body>

<p><b>Welcome to... </b></p>
<div id="div1" style="background:red">Welcome to ...</div>
<div id="div2">Body Background-color ...</div>
<div id="div3">2011 ...</div>
<input type="text" id="txt1">
<input type="button" id="btn1" value="Click">
</body>
</html>


Screenshot

jQuery Css

คำอธิบาย
ตัวอย่างการใช้ css ในรูปแบบต่าง ๆ ซึ่งสามารถดูแล้วเข้าใจได้ไม่ยาก








2. ตัวอย่างการใช้ Selectors เพื่อจัดการ Style Sheet ของ element
ใช้ Selectors อ้างถึง element ที่อยู่ภายใต้ แทกทั้งหมด ที่เรียกใช้ css style sheet เช่น class="test"

Code (jQuery)
<html>
<head>
<title>ThaiCreate.Com jQuery Tutorials</title>
<style type="text/css"> 
	.css1 {
		font-size: 11px;
		font-weight: bold;
		color: #000000;
	}
	.css2 {
		font-size: 20;
		font-weight: bold;
		color: #FF0000;
	}
</style>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){

  $("#btnRemoveCss").click(function(){
    $(".css2").removeClass();
  });

  $("#btnAddCss").click(function(){
    $(".css1").addClass("css2");
  });

});
</script>
</head>
<body>

<p class="css1"> Welcome to jQuery on ThaiCreate.Com Tutorials</p>
<p class="css2"> Version 2011</p>

<input id="btnRemoveCss" type="button" value="Remove Css">
<input id="btnAddCss" type="button" value="Add Css">
</body>
</html>


Screenshot

jQuery Css

คำอธิบาย
จากตัวอย่างมีการเรียกใช้ $(".css1") และ $(".css2") เพื่ออ้างถึง element ที่มี Style Sheet ว่า class="css1" และ class="css2" และมีการ Remove Css และ Add Css เข้าไปใหม่








บทความอื่นๆ เกี่ยวกับ jQuery และ CSS
Go to : jQuery Css and Class : jQuery and CSS คำสั่งพื้นฐาน การเรียกใช้งาน jQuery กับ CSS

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2011-09-21 20:54:42 / 2017-03-19 13:17:25
  Download : No files
 Sponsored Links / Related

 
jQuery : What's a jQuery , jQuery คืออะไร ??
Rating :

 
jQuery : How to use , จะเขียน jQuery จะต้องทำอย่างไร
Rating :

 
jQuery Syntax : jQuery Basic Syntax
Rating :

 
jQuery Selectors : jQuery Selectors and Element
Rating :

 
jQuery HTML : jQuery and HTML
Rating :

 
jQuery Events : jQuery and Events
Rating :

 
jQuery Effects : jQuery and Effects
Rating :

 
jQuery Ajax : jQuery and Ajax
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่