vikramlc / Javascript

0 stars 0 forks source link

Evaluating and Manipulating elements #3

Open vikramlc opened 4 years ago

vikramlc commented 4 years ago

image

vikramlc commented 4 years ago

Attributes vs Properties: image

vikramlc commented 4 years ago

Traversing DOM elements and Manipulating DOM elements: image image

const h1 = document.getElementById('main-title');

h1.textContent = 'Some new title!';
h1.style.color = 'white';
h1.style.backgroundColor = 'black';

const li = document.querySelector('li:last-of-type');
li.textContent = li.textContent + ' (Changed!)';

const body = document.body;

// const listItemElements = document.querySelectorAll('li');
const listItemElements = document.getElementsByTagName('li');

for (const listItemEl of listItemElements) {
  // console.dir(listItemEl);
}

const button = document.querySelector('button');
const section = document.querySelector('section');

section.className = 'red-bg';

button.addEventListener('click', () => {
  section.classList.toggle('invisible');
});
vikramlc commented 4 years ago

image

Difference between children(only 3 elements) vs childNodes(has 7 elements with whitespace as well which are text nodes): image image

vikramlc commented 4 years ago

style: white-space: pre; image

vikramlc commented 4 years ago

Selecting parentNode and parentElement: image

Selecting sibling elements: image