Reading Notes
$('li.hot')
'li.hot'
selector, that refers to all of the <li>
elements with a class of hot
$('li.hot').addClass('complete');
.
Member Operator, indicates that the method on the right should br used to update the elements on the left.addClass('complete');
Method, this method refers to the class attribute and adds the parameter value complete
</div>
<script src="js/jquery-1.11.0.js"></script>
<script src="app.js"></script>
</body>
<li>
elements in the file:
var content = $('li').html(); //will select the first `<li>` element and assign its content to the new variable `content`
$('li').html('updated'); //will update the contents of all `<li>` elements with the word "updated"
$('li[id!="one"]').hide().delay(500).fadeIn(1400);
.ready()
method checks that the page is ready for your code to work with
$(document).ready(function(){
//your script goes here
});
//Shortcut version of same function below
$(function(){
//your script here
});
.html()
retrieves only the content of the first element in the matched set.text()
retrieves all text from the selected elements and their descendants.html()
gives every element in the matched set the same new content which may include html.text()
gives every element in the matched set the same new text, any markup would be shown as plain text.replaceWith()
replaces every element with the new content and returns the replaced elements.remove()
removes all of the elements in a matched setvar $newFragment = $('<li>');
creates a new jQuery object that contains an empty <li>
element
var $newItem = $('<li class="new">item</li>');
creates a new jQuery object that contains an empty an <li>
element with a class attribute and some text.before()
inserts content before the selected element.after()
inserts content after the selected element.prepend()
inserts content inside the element after the opening tag.append()
inserts content inside the element before the closing tag.attr();
method can get or set a specified attributer and its value. To get specify name of attribute in ()
. To set specify both attribute name and new value.removeAttr()
removes attribute by name specified in ()
.addClass()
adds a new value to the existing value of the class attribute, does not overwrite.removeClass()
removes a value from the class attribute, leaving others unchangedvar backgroundColor = $('li').css('background-color');
declares a variable and assigns it the value of the background color of the <li>
element$('li').css('background-color', '#272727')
sets the background color for all <li>
elements to the color #2727272
$('li').css({
'background-color': '#272727',
'font-family': 'Courier'
}) //Sets the background color and font family for all `<li>` elements
.each()
performs one or more statements on each of the items in the selection of elements that is returned by a selectorthis
or $(this)
keyword to access the current element
$('li').each(function(){
var ids = this.id;
$(this).append('<em class="order>' + ids + '</em>');
}) //selection contains all `<li>` elements, `.each()` applies same code to all elements, function run for each item
.on()
method used to handle all events
$('li').on('click', function(){
$(this).addClass('complete');
}); //selects all `<li>` elements, listens for click event which triggers the function to add a class of "complete"
<script src"js/sample.js"></script>
just before the closing </body>
tag.show()
displays selected elements.hide()
hides selected elements.toggle()
toggles between showing and hiding selected elements.fadeIn()
fades in selected elements.fadeOut()
fades out selected elements.fadeTo()
changes opacity of selected elements.fadeToggle()
hides or shows selected element, opposite of current state.slideUp()
hides selected elements with a sliding motion.slideDown()
shows a selected element with a sliding motion.slideToggle()
hides or shows with a sliding motion, opposite of current state.delay()
delays execution of subsequent items in queue.stop()
stops animation if currently running.animate()
creates custom animation
.animate({ styles to change } [, speed] [, easing] [, complete])'