Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js style

const elem = document.getElementById('elem-id');
// Now that we got the element we needed,
// there are 3 ways that we can style it when it's clicked

// method 1: .onclick
elem.onclick = () => {
  elem.style.backgroundColor = 'red';
}

// method 2: .addEventListener
elem.addEventListener('click', function(){
  elem.style.backgroundColor = 'red'; 
})

// method 3: function
function funcName(){
  elem.style.backgroundColor = 'red';
}
// now that we declared the function we need to call it on click,
// we can use both method 1 & 2, replace the code and call the function there
// or we can call it on the html attribute 'onclick'

// <div id="elem-id" onclick="funcName"></div>
Comment

JavaScript Style Guide

firstName = "John";
lastName = "Doe";

price = 19.90;
tax = 0.20;

fullPrice = price + (price * tax);
Comment

js style

const title = document.querySelector('h1')

//title.setAttribute('style', 'margin: 50px');

console.log(title.style); // Show all style propertyes
console.log(title.style.color); // Log a color in console

title.style.margin = '50px'; // Set a margin of title
title.style.color='crimson'; // Set a color of title
title.style.fontSize = '60px'; // Set font size of title
Comment

style through javascript

element.style.backgroundColor = "red";   // set the background color of an element to red
Comment

PREVIOUS NEXT
Code Example
Javascript :: dummy data json 
Javascript :: firebase sign up with email and password 
Javascript :: jquery slideshow autoplay 
Javascript :: javascript audio play on click 
Javascript :: react laravel 
Javascript :: handleClickoutside custom hook react 
Javascript :: break in if statement js 
Javascript :: angular cli no test 
Javascript :: cookies in react native 
Javascript :: javascript telegram bot 
Javascript :: vuejs reset component 
Javascript :: javascript for loop[ 
Javascript :: javascript get next dom element 
Javascript :: Format of fetch 
Javascript :: assign random colors react chartjs 
Javascript :: js two value from array after reduce 
Javascript :: null value check in react js 
Javascript :: take from your discord bot dms discord js 
Javascript :: import and export type in js 
Javascript :: add onclick javascript dynamically 
Javascript :: signed and unsigned integers in JavaScript 
Javascript :: xmlhttprequest object 
Javascript :: add a child html object to another html object in js 
Javascript :: http module nodejs 
Javascript :: expression vs statement javascript 
Javascript :: browseranimationsmodule browsermodule has already been loaded 
Javascript :: nestjs swagger 
Javascript :: salvar no localStorage react 
Javascript :: react-infinite-scroller 
Javascript :: js output to console 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =