Add attribute
$target.attr({"title":"one piece","name":"solgan"});
Add the title and name attributes to the target Element
Before adding:
I am Lu Fei, the man who wants to become the pirate king.
After adding:
I am Lu Fei, the man who wants to become the pirate king.
Remove attribute
$target.removeAttr("title");
Remove an existing style. If the style does not exist, no error is reported.
Before removing a style:
I am Lu Fei, the man who wants to become the pirate king.
After the style is removed:
I am Lu Fei, the man who wants to become the pirate king.
Set Style
$target.attr("class","red");
The so-called set style is actually to modify the class attribute of the target element. Note that this is to change the class to red instead of adding it on the basis of the original class.
Before setting a style:
I am Lu Fei, the man who wants to become the pirate king.
After setting the style:
I am Lu Fei, the man who wants to become the pirate king.
Add Style
$target.addClass("bg");
Add a style based on the original class, instead of replacing
Before adding a style:
I am Lu Fei, the man who wants to become the pirate king.
After adding a style:
I am Lu Fei, the man who wants to become the pirate king.
Delete A style
$target.removeClass("bg");
If the style exists, delete it. If it does not exist, no error is reported.
Before deleting a style:
I am Lu Fei, the man who wants to become the pirate king.
After the style is deleted:
I am Lu Fei, the man who wants to become the pirate king.
Determine whether a style exists
$target.hasClass("bg");
If a style exists, true is returned; otherwise, false is returned.
Add css styles
$target.css("text-decoration","underline");
Before adding a css style:
I am Lu Fei, the man who wants to become the pirate king.
After adding the css style:
I am Lu Fei, the man who wants to become the pirate king.