โดย M008 » 08/06/2013 6:57 pm
:last Selector() เป็นการใช้ Selectors กับ :last Selector() คือในการอ้างถึง element ที่ ลำดับของ index ที่ last หรือ ที่อยู่ในลำดับ สุดท้าย
Syntax
ตัวอย่างการใช้งาน
โค้ด: เลือกทั้งหมด
<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(){
$("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});
});
</script>
</head>
<body>
<table>
<tr><td>First Row</td></tr>
<tr><td>Middle Row</td></tr>
<tr><td>Last Row</td></tr>
</table>
</body>
</html>
ผลลัพธ์
- 16.jpg (11.19 KiB) Viewed 3390 times
คำอธิบายใต้รูป
จากตัวอย่างเป็นการใช้ Selectors กับ :last Selector() ในการอ้างถึง element เช่น $("tr:last") คือการอ้างถึง element ที่ <tr> อยู่ในลำดับสุดท้าย
[b]:last Selector()[/b] เป็นการใช้ Selectors กับ :last Selector() คือในการอ้างถึง element ที่ ลำดับของ index ที่ last หรือ ที่อยู่ในลำดับ สุดท้าย
[b]Syntax[/b]
[code]jQuery(':last')[/code]
[b]ตัวอย่างการใช้งาน[/b]
[code]<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(){
$("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});
});
</script>
</head>
<body>
<table>
<tr><td>First Row</td></tr>
<tr><td>Middle Row</td></tr>
<tr><td>Last Row</td></tr>
</table>
</body>
</html>[/code]
[b]ผลลัพธ์[/b]
[attachment=0]16.jpg[/attachment]
[b]คำอธิบายใต้รูป[/b]
จากตัวอย่างเป็นการใช้ Selectors กับ :last Selector() ในการอ้างถึง element เช่น $("tr:last") คือการอ้างถึง element ที่ <tr> อยู่ในลำดับสุดท้าย