This blog post is about some of the usages of jQuery while I am learning and using jQuery. I keep a note of it so that I can pick it up conveniently later.
- append a paragraph to the front of your body.
1 2 |
|
and also we can do it using the “prepentTo” method.
1
|
|
If we want to insert before/after an element, we can use the following method.
1
|
|
For the “wrap” method, it is like this:
1
|
|
This will wrap all “span”” tag with “strong” tag. Or we can have the nested tags inside “wrap”:
1
|
|
- We can also use callback function to do some selective adding.
1
|
|
- to get the last id attributes of a paragraph:
1
|
|
and to modify its id to “bar”, we can do this:
1
|
|
- if you want to remove an attribute from an element, we can use the “removeAttr” method.
1
|
|
-
text() can just act on “text”, while html() can act on html contents.
-
.val() is used to get the value or content of a form element, like:
1
|
|
or
1
|
|
-
.addClass(), .removeClass(), .toggleClass() are also 3 often used methods.
-
.map() and .each(), .show() and .hide(), .fadeIn(), .fadeOut(), .fadeTo() , these are common methods.