Aug
19
2009
19
2009
การใช้งาน appendTo
มาดูการใช้งาน Function appendTo กันครับ
appendTo นั้นความสามารถของมันคือเราสามารถที่จะ แทรก Tag หรือ elements อื่นๆเข้าไปใน
elements ที่เราต้องการได้
เช่น
1 2 3 4 5 6 7 8 | <script> $(document).ready(function(){ $('span').appendTo('#foo'); }); </script> <span>I am a Programmer.</span> <p id='foo'>Hello,</p> |
จาก Code ด้านบน จะเห็นว่าจะมี Element อยู่สองตัวด้วยกันคือ SPAN กับ P
ถ้าหากเรายังไม่ได้ใช้ appendTo นั้นการแสดงผลของ Element ทั้งสองจะเป็นแบบนี้ครับ
1 2 | <span>I am Programmer</span> <p>Hello,</p> |
และเมื่อเราใช้ appendTo แล้วมันจะเอา Element SPAN มาแทรกใน P แบบนี้ครับ
1 | <p>Hello, <span>I am programmer</span> </p> |
จะเห็นว่าประโยชน์นี้ เราเอาไปใช้งานกับการ ทำงานแบบ ajax ได้เช่น ถ้านำไป update element ที่ต้องการ
สามารถย้าย element ที่ต้องการไปใว้ใน element อื่นๆได้เป็นต้น การนำไปใช้งานนั้นก็ขึ้นอยู่กัน ไอเดีย ของแต่ละคนว่าจะเอาไปทำอะไรต่อได้อีก
Tags
.data
access iframe
advance
Ajax
attr
bind
browser
canvas
Core
debugs
Deferred
deferred.then
Deferred Object
delegate
DOM
Effect
event
Events
filters
google
HTML
html5
iframe
Image
jquery
jquery.data
jQuery 1.4
jquery 1.5
jQuery 1.6
jQuery 1.7
jquery mobile
jquery plugin
jquery ui
json
live
Plugin
plugins
selector
Selectors
show()
UI
undelegate
validate
welcome
what's jquery
Facebook Development
Google+ Page
Categories
- HTML5 & CSS3 (8)
- jQuery 1.4 (9)
- jQuery 1.5 (6)
- .data (1)
- jQuery 1.6 (3)
- .data (1)
- jQuery 1.7 (4)
- Events (1)
- jQuery Mobile (3)
- jQuery UI (3)
- Mobile (1)
- News (8)
- Others (28)
- Plugin (15)
- The basics of jQuery (9)
- Tips (13)
- คู่มือการใช้งาน jQuery ฉบับ ภาษา ไทย (30)
- Ajax (4)
- Attributes (1)
- Core (1)
- Deferred (3)
- Effects (7)
- Events (3)
- Manipulation (2)
- Selectors (5)
- Traversing (2)
- Utilities (2)

An article by







