New blog location
New blog location
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>jQuery</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1 class="big-title">Hello</h1> <button>Click Me</button> <button>Click Me</button> <button>Click Me</button> <button>Click Me</button> <button>Click Me</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="index.js" charset="UTF-8"></script> </body> </html>
$("h1").css("color","red");
$("h1")
selects all the h1
s.console.log($("h1").css("font-size"));
$("h1").addClass("big-title");
.big-title { font-size: 10rem; font-family: cursive; }
$("h1").addClass("big-title margin-25");
$("h1").hasClass("margin-25")
.$("h1").text("Later")
to change the text. Because jQuery selects all matching elements, if there are multiple elements that are selected, then all are affected.$("h1").html("<strong>Hi</strong>")
.console.log($("img").attr("src"));
$("a").attr("href", "https://www.yahoo.com");
<h1 class="big-title margin-25">Hello</h1>
$("h1").attr("class")
big-title margin-25
.h3
:$("h3").click(function () { $("h3").css("color","red"); });
$("button").click(function() { $("h1").css("color","purple"); });
$("input").keydown(function(evt){ console.log(evt.key); });
$(document).keydown(function(evt)){ console.log(evt.key); });
on
:$("h1").on("mouseover",function() { $("h1").css("color","purple"); });
$("h1").before("<button>New</button>"); $("h1").after("<button>New</button>"); $("h1").prepend("<button>New</button>"); //add new HTML element inside the tag. $("h1").append("<button>New</button>"); //again, append inside the h1 tag.
$("button").remove(); //removes all buttons
$("h1").hide(); //hides the h1 $("h1").show(); //shows the h1 $("h1").toggle(); //toggle the h1
$("h1").fadeOut(); $("h1").fadeIn(); $("h1").fadeToggle(); $("h1").slideDown(); $("h1").slideUp(); $("h1").slideToggle();
$("h1").animate({opacity: 0.5}); //can only use numeric values.
$("h1").slideUp().slideDown().animate({opacity: 0.5});
Comments
Post a Comment