JAVASCRIPT change background color element by every click javascript - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

How to change the background color of element by every click using javascript ?


 199

Show ResultJAVASCRIPT


1

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>

<button onclick="change()">Click</button>
<p style="background-color: orange;">Hello jquery!</p>

<script type="text/javascript">

function change_color() {

var color = document.getElementsByTagName("p")[0].style.backgroundColor;

if (color === 'orange') {

document.getElementsByTagName("p")[0].style.backgroundColor = "green";
}

else {

document.getElementsByTagName("p")[0].style.backgroundColor = "orange";
}

}


function change() {

change_color();

}

</script>

</body>
</html>


By        
The power of the user (%)
11%



The most helpful JAVASCRIPT solutions

How to get client machine name or computer name with javascript ?How to get client machine name or computer name with javascript ?JAVASCRIPT

Click to see more ...

  13.4K     391

get client hostname javascriptget client hostname javascriptJAVASCRIPT

Click to see more ...

  4.1K     274

detect ie javascriptdetect ie javascriptJAVASCRIPT

Click to see more ...

  2.5K     192

Create fireworks using javascriptCreate fireworks using javascriptJAVASCRIPT

Click to see more ...

  2.4K     161

fire event when user is idle javascriptfire event when user is idle javascriptJAVASCRIPT

Click to see more ...

  2.1K     153

Create progress bar using javascriptCreate progress bar using javascriptJAVASCRIPT

Click to see more ...

  1.3K     152

how to create foreach class using javascript ?how to create foreach class using javascript ?JAVASCRIPT

Click to see more ...

  1.7K     112

create 3d barrel using javascriptcreate 3d barrel using javascriptJAVASCRIPT

Click to see more ...

  1.9K     112

create qr code javascriptcreate qr code javascriptJAVASCRIPT

Click to see more ...

  1.6K     106

create earth in universe with three.jscreate earth in universe with three.jsJAVASCRIPT

Click to see more ...

  1.4K     90