JQuery:
1. Preventing default event (in this case the default being the opening of a link when you click it):
$(document).ready(function() {
$(’a’).click(function(event){
event.preventDefault();
alert(”Bye!”);
});
});
2. Selecting DOM elements with JQuery:
$(document).ready(function() {
var container =$(’.container’);
var someId = $(’#someId’)
var menu = $(’.menu’);
console.log(’container ’, container);
console.log(’some Id ’, someId);
console.log(’menu ’, menu);
var menuPlusLi = $(’.menu li’);
console.log(’menuPlusLi’, menuPlusLi);
var menuFirstElement = $(’.menu2 li:first’);
console.log(’menuFirstElement ’, menuFirstElement);
});
3. JQuery cheat sheet: https://oscarotero.com/jquery/
4. Changing the name of a class with JQuery and adding a new class:
console.log(’menu2 class name ’, $(’.menu2’).attr(’class’, ’menu3’));
console.log(’menu2 class name ’, $(’.menu2’).addClass(’newClass’));