Example: Bold link text containing "wangorg" characters
css:
.abold{
font-weight:bold;
}
html:
$('document').ready(function(){
$('a[href* =wangorg]').addClass('abold');
})
Attribute selection can also be combined:
$('a[href^=http]
[href*=wangorg]').addClass('abold')
The custom selector is a unique and completely different selector added by JQUERY. The syntax is the same as the pseudo-class selector syntax in CSS. , that is, the selector starts with a colon (:).
For example: Select the second item from the matching div collection with wangorg class, the corresponding syntax is: $('div.wangor:eq(1)')
The CSS selector syntax is $ ('div:nth-child(2)')
Example: Change the background color of the even rows of the table to #ccc
CSS:
.alt{
backgroud-color:#ccc;
}
HTML:
$('document').ready(function() {
$('tr:odd').addClass('alt')
})
Change all tables in the web page to the above effect:
$('document').ready(function(){
$('tr:nth-child(even)').addClass('alt');
})
Add the font of the table containing the "wangorg" string in the table Thick
$('document').ready(function( ){
$('tr:contains(wangorg)').addClass('abold');
})
Related selector explanation:
:eq(index )
The elements in the result set that are after (greater than) the given index (starting from 0)
:odd
All odd elements in the result set (starting from 0)
:even All even numbers in the result set Element (starting from 0)
:nth-child(even)
The element that is the even-th child element of its parent (counting from 1)
:contains(text) Element that contains the given text text .