You don't really need jQuery to manipulate the DOM. Here are 10 popular methods for manipulating the DOM 💈
1. document.querySelector(#name) //returns the 1st element from the DOM with the id of name.
2. document.getElementbyId(head) //returns an element with id of head
Next👇
3. var btn =document.querySelectors(.btn) //returns ALL elements from the DOM with a class of btn.
4. btn.addEventListener('click', foo); // calls a function (foo) anytime 'btn' element is clicked
5. btn.removeEventListener('click',foo); //detaches event listener from btn.
👇
6. var Para = document.createElement('p')
//creates a paragraph element in JavaScript. Not in DOM yet
7. var strong = document.createElement('strong');
strong.textContent = 'Hello';
p.appendChild(strong);
//textContent adds inner text
//strong is then nested inside paragraph
8. p.removeChild(strong); //removes the previously inserted strong element
9. var em = document.createElement('em');
var strong = document.querySelector('strong');
var p = document.querySelector('div');
em.textContent = 'hi';
p.replaceChild(em, strong);
// replaces strong
10. var em = document.createElement('em');
var strong = document.querySelector('strong');
var div = document.querySelector('div');
em.textContent = 'hi';
div.insertBefore(em, strong);
//Inserts em before strong inside div.
Others:
cloneNode()
getAttribute()
getAttribute()
• • •
Missing some Tweet in this thread? You can try to
force a refresh
VARIABLES
- Variable names are case sensitive (name and NAME are
different variables)
- Must start with a letter or an underscore
- Can have numbers but must not start with one
- Python is loosely-typed (you don’t specify the type when
declaring a variable.
FUNCTIONS
- In python, functions are defined with the def keyword.
- Indentation is used instead of curly braces.
- A colon is placed after the parameters.
- No semi-colons.
🌟 2: #null essentially means "no data", empty, nada. #undefined means data has not been explicitly defined or declared. #boolean evaluates to either true or false. #numbers are digits between 0-9, #strings are characters enclosed within double quotes