jQuery in Action phần 4

Tham khảo tài liệu 'jquery in action phần 4', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Manipulating element properties and attributes 51 For the most part the name of a JavaScript attribute property matches that of any corresponding attribute but there are some cases where they differ. For example the class attribute in this example is represented by the className attribute property. jQuery gives us the means to easily manipulate an element s attributes and gives us access to the element so that we can also change its properties. Which of these we choose to manipulate depends on what we want to do and how we want to do it. Let s start by looking at getting and setting element properties. Manipulating element properties jQuery doesn t possess a specific command to obtain or modify the properties of elements. Rather we use the native JavaScript notation to access the properties and their values. The trick is in getting to the element references in the first place. The easiest way to inspect or modify the component elements of a matched set is with the each command. The syntax of this command is as follows Command syntax each each iterator Traverses all elements in the matched set invoking the passed iterator function for each. Parameters iterator Function A function called for each element in the matched set. The parameter passed to this function is set to the zero-based index of the element within the set and the element itself is available as the this property of the function. Returns The wrapped set. This command can be used to easily set a property value onto all elements in a matched set. For example consider img .each function n This is image n with an id of This statement will invoke the inline function for each image element on the page modifying its alt property using the order of the element and its id value. Note that because this is an attribute property tied to an attribute of the same name the alt attribute is also indirectly updated. 52 CHAPTER 3 Bringing pages to life with jQuery Similarly we can collect all .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
15    22    4    30-11-2024
Đã 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.