$("p").css("color", "red");
<p>
elements and change their text color to red . $("#toggle-btn").click(function(){ $("#target-element").toggleClass("active"); });
toggle-btn
. Every time the button is clicked, the element with the id of target-element
will toggle the active
class name. $("#fade-in-btn").click(function(){ $("#target-element").fadeIn(); }); $("#fade-out-btn").click(function(){ $("#target-element").fadeOut(); });
fade-in-btn
and fade-out-btn
. When the fade-in button is clicked, the element gradually displays, and when the fade-out button is clicked, the element gradually hides. $("#slide-down-btn").click(function(){ $("#target-element").slideDown(); }); $("#slide-up-btn").click(function(){ $("#target-element").slideUp(); });
slide-down-btn
and slide-up-btn
. When the slide-down button is clicked, the element slides down and displays, and when the slide-up button is clicked, the element slides up. hide. $("#hover-element").hover(function(){ $(this).css("color", "blue"); }, function(){ $(this).css("color", "black"); });
hover-element
, and return to black when the mouse is removed.
<p>Through the above examples, we can see that jQuery provides a wealth of methods and events to achieve diverse changes in web page styles. Developers can flexibly use these methods according to specific needs to make web pages more lively and interesting. Hope this article is helpful to you! The above is the detailed content of jQuery to expand web page style diversity. For more information, please follow other related articles on the PHP Chinese website!