Javascript without jQuery

A word on jQuery

What do we use jQuery for?

Why would you skip jQuery?

Native DOM Selection

$('#thing');
document.getElementById('thing');
$('.things');
document.getElementsByClassName('things');
$('input');
document.getElementsByTagName('input');
$('#thing .list li');
document.querySelector('#thing .list li');

Reading the DOM

Manipulating the DOM

$('#thing').html('<p>hello<p>');
document.getElementById('thing').innerHTML = '<p>hello<p>';
$('.things').append('<span>thing<span>');
document.querySelector('.things').innerHTML += '<p>hello<p>';
var thing = document.createElement('p');
document.querySelector('.things').appendChild(thing);
      
$('#thing p').remove();
document.getElementById('#thing').removeChild('p');

Animation/DHTML

$('#thing').animate({top:'12px', left: '12px'});
document.getElementById('thing').classList.add('tadaa');
#thing{
  position:absolute;
  top:0px;
  left:0px;
  transition:all 0.5s ease-out;
}

#thing.tadaa{
  top:12px;
  left:12px;
}
      

Handling Events

$('#thing').click(function(){console.log('hello world!');});
document.getElementById('thing').addEventListener('click', function(){
  console.log('hello world!');
}, false);
$(window).trigger('newMessage', { message: "Hello World!", time: new Date()})
var event = new CustomEvent(
  "newMessage",
  {
    detail: {
      message: "Hello World!",
      time: new Date()
    },
    bubbles: true,
    cancelable: true
  }
);
window.dispatchEvent(event);
      

Discovering the DOM

Cross Browser Compatability

underscore js

An alternative: microframeworks

An Admission

Useful Links