3 selector: Element selector: $("button")
, class selector: $(".btn")
, ID selector: $("#target1")
.
<Script>$ (document). Ready (function() { $("Button"). addclass ("Animated Bounce"); $(". Well"). addclass ("animated Shake"); $("#target3"). addclass ("animated FadeOut"); $("Button"). Removeclass ("Btn-default");
$ ("button"). Remove ("#target4"); });</Script>
jquery has a .css()
method called that allows you to change the CSS style of an element.
Here's how we're going to change the color to blue:
$("#target1").css("color", "blue");
This is a bit different from the usual CSS syntax, where the properties and values of CSS are enclosed in quotation marks and separated by commas.
Let's try moving elements from one div
to the other div
.
jquery has a appendTo()
way to add selected elements to other elements.
For example, if you want to target4
move from our right-well
to left-well
, we can use this:
$("#target4").appendTo("#left-well");
In addition to moving elements, you can also copy elements. Simple to understand: Moving an element is cut, copying the element is copying.
The jquery clone()
method can copy elements.
For example, if I want target2
to left-well
copy from to right-well
, we can write this:
$("#target2").clone().appendTo("#right-well");
Have you found that two jquery methods are used together? This is called the method chain function chaining
, easy to use.
<Script>$ (document). Ready (function() { $("#target1"). CSS ("Color", "Red"); $("#target1"). Prop ("Disabled", true); $("#target4"). Remove (); $("#target2"). AppendTo ("#right-well"); $("#target5"). Clone (). AppendTo ("#left-well"); });
The jquery .html()
method can add HTML tags and text to an element, and the content before the element is replaced by the contents of the method.
We use em
the [emphasize] tab to rewrite and emphasize the title text:
$("h3").html("<em>jQuery Playground</em>");
JQuery also has a similar method called .text()
, which can only change the text but cannot modify the tag. In other words, this method only displays anything that comes in (including tags) as text.
Introduction to jquery the next day