jQuery Basics Flashcards
What are the Four P’s of problem solving
P preparation
P planning
P Perform
P Perfect
What is preparation in the four P’s of problem solving?
The first P is preparation, where we try to understand the problem and think of a solution.
What is planning in the four P’s of problem solving?
The second P is planning, where we plan out the solution.
What is Perform in the four P’s of problem solving?
The third P is perform, where we perform what’s required for our proposed solution.
What is Perfect in the four P’s of problem solving?
Fourth is we’ll perfect our solution if there’s any mistakes or things that we haven’t considered yet.
.hide()
Hide the matched elements.
.hide()
With no parameters, the .hide() method is the simplest way to hide an element:
$( “.target” ).hide();
.show()
Display the matched elements.
.show()
With no parameters, the .show() method is the simplest way to display an element:
$( “.target” ).show();
How to show an element slowly.
$( “button” ).click(function() {
$( “p” ).show( “slow” );
});
.ready( handler )
Specify a function to execute when the DOM is fully loaded.
.ready( handler )
handler
Type: Function()
A function to execute after the DOM is ready.
* $( document ).ready( handler ) * $( handler )
$( document ).ready(function() { // Handler for .ready() called. });
.append()
.append()
Insert content, specified by the parameter, to the end of each element in the set of matched elements.
.append( content [, content ] )
$( “.inner” ).append( “<p>Test</p>” );
.click()
Bind an event handler to the “click” JavaScript event, or trigger that event on an element.
.click( handler )
◦ handler
Type: Function( Event eventObject )
A function to execute each time the event is triggered.
$("button").click(function(){ //3.1 We want to show the spoiler next to the button clicked. $(this).prev().show(); //3.2 Get rid of the button $(this).remove(); });
.remove()
Remove the set of matched elements from the DOM.
<div class="container"> <div class="hello">Hello</div> <div class="goodbye">Goodbye</div> </div> We can target any element for removal:
$( “.hello” ).remove();
This will result in a DOM structure with the <div> element deleted:
<div>
<div>Goodbye</div>
</div>
</div>
.prev()
Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided, it retrieves the previous sibling only if it matches that selector.
<ul> <li>list item 1</li> <li>list item 2</li> <li class="third-item">list item 3</li> <li>list item 4</li> <li>list item 5</li> </ul> To select the element that comes immediately before item three:
$( “li.third-item” ).prev().css( “background-color”, “red” );
.attr()
Get the value of an attribute for the first element in the set of matched elements.
.attr( attributeName )
$(“#imageGallery a”).click(function(event){
$(this).attr(“href”);
console.log();
});
event.preventDefault()
If this method is called, the default action of the event will not be triggered.
$( "a" ).click(function( event ) { event.preventDefault(); $( "<div>" ) .append( "default " + event.type + " prevented" ) .appendTo( "#log" ); });</div>