JavaScript Background Color Change

Blog Gönderisi Resmi

Click to get information about our services.

Colors are very important in the web development process, both at the design and coding stages. Correct use of the colors determined by the designers during the coding stage increases the quality of the website. At this point, the document.body.style.BackgroundColor property comes into play.

The document.body.style.BackgroundColor property is a command used in the JavaScript language and is used to determine the background color of the web page. Through this feature, the background color of the web page can be easily changed to different colors.

Sample Code:


<div>
    <button onclick="arkaplankirmizi()">Beyaz Yap</button>
</div>
<script>
    function arkaplankirmizi() {
        document.body.style.backgroundColor = "red";
    }
</script>

In the example above, a button was created in a div, the "onclick" property was given to the button, and the JavaScript code that should be run when clicked was added. If you want it to change when you touch a picture with the mouse or a text when you touch it with the mouse, you should use "onmouseover".

Thanks to this feature, the background color of web pages can be changed to match the colors of your brand or the purpose of the site. For example, you can choose pastel colors for a fashion blog, or use darker colors for a technology-focused site.

CODES

See the Pen Untitled by EnesAlp (@enesalpcomtr) on CodePen.

What We Recommend For You

Blog Resim
What is Next.js? What are the Advantages and Features?

JavaScript

Next.js, one of the most preferred tools by developers when creating web applications and sites, is a framework that works on the basis of React ..

Read More
Blog Resim
Vue.JS Nedir? Nerelerde Kullanılır?

JavaScript

Vue.JS, açık kaynak bir JavaScript hızlı geliştirme uygulama çerçevesidir. Vue.JS, tek sayfalı uygulamalar (SPA) oluşturmak için kullanılabilecek ..

Read More
Blog Resim
Vue.js'ye Başlamak ve Vue.JS Kurulumu

JavaScript

Vue.js son yıllarda popüler hale gelen JavaScript kütüphanesi ve framework'üdür. Özellikle Single Page Applications (SPA) oluşturma konusunda ..

Read More
Blog Resim
JavaScript’te Asenkron Programlama Nedir?

JavaScript

JavaScript, web uygulamalarının en yaygın kullanılan programlama dillerinden biridir. Ancak, web uygulama geliştiricileri genellikle JavaScript'teki ..

Read More