jQuery Basics Flashcards
shorthand for jQuery
$
select the element with the CSS class of warning
$(“.warning”)
Remember that CSS classes start with a period
hide warning when the page loads and then show it slowly
$(“.warning).hide().show(“slow”)
open Chrome Developer Tools
Command + Option (Alt) + J
go over to previous line of code
the up key
display the function myCode after the DOM has loaded
$(document).ready(myCode)
add a button to the spoiler class
$(“.spoiler).append(“Reveal Spoiler “);
add a click handler to the button, show the spoiler and remove the button
$(“button”).click(function(){
$(“.spoiler.span”).show();
$(this).remove();
});
show the spoiler next to the button clicked
$(this).prev().show();
Capture the click event on a link to an image (with the ul id=”imageGallery”)
$(“#imageGallery a”).click();
prevent browser default behavior
$(“#imageGallery a”).click(function(event){
event.preventDefault();
Using jQuery only, add to all links with the class “external”, the target attribute with the value of “_blank”.
$(“a.external”).attr(“target”,”_blank”);
create a detached select object of the DOM
$select = $(“”);
A prompt dialog will open prompting for someone’s full name. Use jQuery to follow the comments in code. First, select the correct input, and then set its value to the fullName.
//Show Prompt Window and store value var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName //Insert value in to full name input
//Show Prompt Window and store value var fullName = prompt("What is your full name?");
//Select Input with the id of #fullName //Insert value in to full name input $('#fullName').val(fullName);
/* $('#fullName') -> selects the input with this id. .val() -> JQuery method to get a value from an element or set the value if a value is passed. In this case, we set the value of the input to the value we get from the prompt. */
use a single jQuery method to either show or hide the $(“#colorSelect”)
$(“#colorSelect”).toggle();