1. Four ways to add jQuery.
(1) .append(), which inserts content at the end of the selected element.
(2) .prepend(), which inserts content at the beginning of the selected element.
(3).After(), insert content after the selected element.
(4) .before(), insert content before the selected element.
grammar:
$('Selected element').append('Added content')
2.extend() method
var object1={name:'li',age:'15',sex:'男'} var object2={name:'wang',age:'13'} jQuery.extend(object1,object2)
result:
object1={name:'wang',age:'13',sex:'男'}
Role: merge object1, object2, and replace the content.
3.addClass() Adds a class to the specified element.
$('selected element').addClass('specify class name 1 specify class name 2') //Use removeClass() to remove classes and add new ones. $('Selected element').removeClass('Specify the class to be removed').addClass('Added class')
4.attr() Add and change the attributes and values of the specified element.
$('img').attr('width','100px') $('img').attr('width',function(){})//Available function methods. $('img').attr({key:value,key1:value1,...})//Specify one or more
.removeAttr() removes the specified attribute from all matching elements.
5.hasClass() Checks whether the specified element has the specified class.
$('specified element').hassClass('classname')
6.val() Sets or returns the value of the specified element.
<inputs type='text' value='map'/> alert($('inputs:text').val()) The output is a map.
7. grep() method to remove items from the array as needed
var arr = [1,5,6,9,7,8,5] var arr=jQuery.grep(arr,function(a){return a!==5}) Result: arr=[1,6,9,7,8]