Today is my first day of learning jQuery. The main learning content is as follows: 1. compile the events after the web page is loaded; 2. jQuery selector usage; 3. jQuery obtains/modifies TAG content and obtains/Tag attribute values. 4. jQuery hide/display tags 5. jQuery adds Click... syntaxHighlighter.
Today is my first day of learning jQuery. The main learning content is as follows:
1. Compile the events after the web page is loaded;
2. How to Use the jQuery selector;
3. jQuery obtains/modifies TAG content and obtains/Tag attribute values;
4. jQuery hide/display tags
5. jQuery's method of adding a Click event to a tag
Learning Experience:
1. How to automatically hide/display tag Blocks
Idea => set a custom attribute for the hide/Show button, as shown in the following code:The operation attribute of is customized. It has two values ('hide '/'show') and the default value is 'hide, use jQuery to change the value once (between the two values of hide and show). When hiding or displaying a tag block, you only need to determine the value of the operation attribute.
In addition, we will introduce jQuery's simple method for implementation:
$ ('Input # toggleaction'). click (function (){
$ ('Div # hideOrShowDiv '). toggle ();
});
It's so easy...
2. Get/set the value of a tag attribute
$ ("Tag"). attr ("attribute name"); // get the attribute value
="
$ ('Div '). attr ('id ');
$ ('Div # idname'). attr ('id ');
$ ('Div. classname'). attr ('id ');
$ ("Tag"). attr ('Property name', 'Property attribute'); // set the property value
="
$ ('Div '). attr ('id', 'xxvalue ');
$ ('Div # idname'). attr ('id', 'xxvalue ');
$ ('Div. classname'). attr ('id', 'xxvalue ');
3. Usage of hide () & show ()
Hide tags: $ ('tagname'). hide ();
Show tags: $ ("tag name"). show ();
4. Obtain the tag Text Value
$ ('Div # hideOrShowDiv '). text ()
5. Insert text to a specified tag
Condition ('div=hideorshowdiv'{.html ("contentValue ");
------------------------------- The code is pasted here for your reference. It is not well written and mainly used for your own learning ------------------------------
JQuery Practice 1: The Write Less, Do More, JavaScript Library