Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add style javascript

// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
Comment

how to change style of an element using javascript

<html>
<body>

<p id="p2">Hello World!</p>

<script>
document.getElementById("p2").style.color = "blue";
</script>

<p>The paragraph above was changed by a script.</p>

</body>
</html>
Comment

adding styling to element using javascript

var elem = document.querySelector('#some-element');

// Set color to purple
elem.style.color = 'purple';

// Set the background color to a light gray
elem.style.backgroundColor = '#e5e5e5';

// Set the height to 150px
elem.style.height = '150px';
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js kill process 
Javascript :: how to change background color on scroll 
Javascript :: adding js file to reactjs 
Javascript :: prettier vscode settings 
Javascript :: javascript returning a function 
Javascript :: get value for radio button in jquery label 
Javascript :: json.stringify vs json.parse 
Javascript :: js object using variable as key 
Javascript :: preview upload image js 
Javascript :: nepali date picker 
Javascript :: javascript check if two arrays contain same values 
Javascript :: javascript keyup event enter key 
Javascript :: how to get common elements from two array in javascript using lodash 
Javascript :: remove all duplicates from an array 
Javascript :: select in react with nchange 
Javascript :: jquery convert time to 1day 2 minutes 4 seconds 
Javascript :: es6 method definition syntax 
Javascript :: countdown in js 
Javascript :: run onclick function once js 
Javascript :: can you call a function within a function javascript 
Javascript :: jquery select first matching element 
Javascript :: post jquery 
Javascript :: Jscript for date suffix 
Javascript :: js get selected option element 
Javascript :: Use Multiple Conditional Ternary Operators Javascript 
Javascript :: js how to filter only real numbers from decimals 
Javascript :: how to reade selected csv file data in node j s 
Javascript :: send mail, nodemailer, nodemailer, mailer, nodemailer npm 
Javascript :: equivalent method load jquery with javascript 
Javascript :: determine if touch screen js 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =