tailieunhanh - Wordpress 3.0 jQuery - part 9

Tham khảo tài liệu 'wordpress jquery - part 9', công nghệ thông tin, đồ họa - thiết kế - flash phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Working with jQuery in WordPress Within the Attributes API of jQuery you ll find more CSS manipulation features such as the .addClass .removeclass and .toggleclass. These three functions alone will give you a lot of power in making your WordPress site dynamic. Don t be confused by my continued talk of attributes We re not dealing with selectors and filters anymore. We re dealing with functions that allow you to manipulate those selections. Let s take a look at some of jQuery s CSS and class attribute manipulation functions in detail Example Syntax Description .css property value jQuery .post .css background f60 Adds or changes the CSS properties of the selected elements. .addClass className jQuery .post .addClass sticky Adds listed class es to each of the selected elements. .removeClass className jQuery .post .removeClass sticky Removes listed class es from each of the selected elements. .toggleClass className switch-optional jQuery .post .toggleClass sticky Toggles listed class es from each of the selected elements based on their current state. If the class is there it s removed and if it s not it s added. .hasClass className jQuery .post .hasClass sticky Returns true or false if listed class es from each of the selected elements exist. Let s check out that addClass function by adding the default s theme sticky class to all posts. When making selections you ll need to denote class names from id names from tag names but in these jQuery class attribute functions you only need to put in the name of the class. You don t need to denote it with a . period. The function is only expecting a class name so it s not necessary. As you might expect you obviously can t add an id name to a selection using the addClass function and nope sorry there s no addId function jQuery .post .addClass sticky 66 Chapter 2 You can now see in the next screenshot that the .sticky class has been added to all the .post classes through jQuery not WordPress Manipulating attributes You can also .