TAILIEUCHUNG - Học JavaScript qua ví dụ part 72

Trước khi chèn một Node Các insertBefore () phương pháp cho phép bạn chèn một nút con trước khi các nút xác định, được gọi là các nút tham chiếu, và nếu các nút tham chiếu là null, điều này sẽ chèn các nút vào cuối danh sách các nút con. | 636 Chapter 15 The W3C DOM and JavaScript Inserting Before a Node The insertBeforeO method allows you to insert a child node before the specified node called the reference node and if the reference node is null this will insert the node at the end of a list of child nodes. FORMAT insertBefore newElement targetElement EXAMPLE newPara firstPara Example demonstrates how to insert a new paragraph node into a DOM before another node. EXAMPLE html head title Inserting Before title style type text css p font-style arial color darkblue font-size 18 style script type text javascript 1 function insertMessage 2 var newPara p 3 var newText I am inserting myself above you If you copy this don t break the lines. 4 newText 5 var firstPara firstp 6 newPara firstPara script head 7 body onload insertMessage p id firstp I was supposed to be first. p body html EXPLANATION 1 Once the page has loaded this function will be called. 2 With the createElement method a new paragraph is created. A reference to it is assigned to a variable newPara. From the Library of Modifying the DOM Appending Copying and Removing Nodes 637 EXPLANATION 3 Now we are going to insert some text into the paragraph with the createTextNode method. 4 After creating a reference to the new text it is appended to the paragraph with the appendChild method. 5 The returns a reference to the first paragraph. This will be the reference node or the node in which the second paragraph will be inserted. 6 The new paragraph is inserted above the first paragraph see Figure . 7 When the page is loaded this function will be called. It will cause a new paragraph to be inserted above the paragraph identified below this line with the id firstp. Figure The DOM insertBefore method. Creating Attributes for Nodes The .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.