1.Manipulating element properties
Command syntax: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.
eg: $('img').each(function(n){
this.alt='This is image['+n+'] with an id of '+this.id;
});//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.
2.Fetching attribute values
Command syntax:attr(name)
Obtains the values assigned to the specified attribute for the first element in the matched set.
The attr() command can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements.
Parameters
name (String) The name of the attribute whose value is to be fetched.
Returns
The value of the attribute for the first matched element. The value undefined is returned if
the matched set is empty or the attribute doesn’t exist on the first element.
3.Setting attribute values
Command syntax:attr(name,value)
Sets the named attribute onto all elements in the wrapped set using the passed value.
Parameters
name (String) The name of the attribute to be set.
value (String|Object|Function) Specifies the value of the attribute. This can be any JavaScript expression that results in a value, or it can be a function. See the following
discussion for how this parameter is handled.
Returns
The wrapped set.
eg: $('*').attr('title',function(index) {
return 'I am element ' + index + ' and my name is ' +
(this.id ? this.id : 'unset');
});
$("a[href^=http://]").attr("target","_blank");// set all the links open in a new window!
Command syntax:attr(attributes)
Sets the attributes and values specified by the passed object onto all elements of the matched set
Parameters
attributes (Object) An object whose properties are copied as attributes to all elements in the wrapped set
Returns
The wrapped set
eg: $('input').attr(
{ value: '', title: 'Please enter a value' }
);
note: Internet Explorer won’t allow the name attribute of <input> elements to
be changed. If you want to change the name of <input> elements in
Internet Explorer, you must replace the element with a new element pos-
sessing the desired name.
4.Removing attributes
Command syntax:removeAttr(name)
Removes the specified attribute from every matched element
Parameters
name (String) The name of the attribute to be removed
Returns
The wrapped set
分享到:
相关推荐
Chapter 10: Properties and Events Chapter 11: Interfaces Chapter 12: Manipulating Classes Chapter 13: Objects and Memory Part III Chapter 14: Generics Chapter 15: Anonymous Methods Chapter 16: ...
关于PDF文件制作及操作的经典书籍,适用于java C#等多种语言,可以添加图片,水印,各种字体,报表,教你如何一步一步的成为PDF编程高手,真正的step by step,深入浅出,五步即可制作自己的PDF文件。
Series of MATLAB scripts and functions for manipulating ADCIRC meshes, interpolation of bathymetry, and calculation of specific quantities.zip
John Resig is an acknowledged JavaScript authority and the creator of ...Cutting through attributes, properties, and CSS PART 4 MASTER TRAINING Surviving events Manipulating the DOM CSS selector engines
发表在CODASPY‘16上的论文 SMASheD: Sniffing and Manipulating Android Sensor Data。作者利用ADB的漏洞,可以在不需要root的设备上劫持、篡改和盗取设备的传感器数据。 摘要 现在的传感器的安全模型主要是限制APP...
Loading and Manipulating Data Section 12.1. Working with QueryTable Objects Section 12.2. QueryTable and QueryTables Members Section 12.3. Working with Parameter Objects Section 12.4. ...
In this book, you will learn how to author an SVG document using common SVG features, such as elements and attributes, and serve SVG on the web using simple configuration tips for common web servers....
Manipulating tab order and focus 141 Chapter 5: Application and Windows 145 Introduction 145 Creating a window 145 Creating a dialog box 149 Using the common dialog boxes 153 Creating ownership ...
Manipulating Processes and Signals Chapter 7. System Calls Chapter 8. Editors in Unix Chapter 9. AWK Script Chapter 10. Bourne Shell Programming Chapter 11. Korn Shell Programming Chapter 12. C Shell...
A follow-up to the perennial best-seller Gray Hat Python (2011), the all-new Black Hat Python explores the darker side of Python's capabilities—writing network sniffers, manipulating packets, web ...
Succinctly and clearly written, this book examines dozens of real-world uses of the Canvas API, such as interactively drawing and manipulating shapes, saving and restoring the drawing surface to ...
building databases from scratch, manipulating images and sending out e-mails using PHP, authenticating users, managing content through CMS, creating a mailing list, setting up an e-commerce section, ...
- **Numerical Operations on Arrays:** Performing arithmetic operations, statistical computations, and element-wise operations. - **More Elaborate Arrays:** Creating arrays with specific properties, ...
- **Variables:** Understanding and manipulating variables is crucial in any programming language. Variables are placeholders for data that can change during program execution. You'll learn how to ...
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,被广泛用于Web服务和应用程序之间的数据传输。在C语言环境中,处理JSON数据通常需要借助专门的库,本压缩包提供的就是一个C语言编写的用于编码、...
Manipulating data Developing and deploying reliable applications PRACTICE TESTS Assess your skills with the practice tests on CD. You can work through hundreds of questions using multiple testing ...