S
S
sokol11112020-04-29 20:29:30
JavaScript
sokol1111, 2020-04-29 20:29:30

How to remove the background-color from an element?

Good day.
Tell me how, when clicking on the #btn block, take the value of the background-color attribute from the #box1 element and display it as text in the #box-text block. It seems that it is not difficult, but it does not work.

<div id="box1" style="background-color: #cccccc; width: 100px;height: 100px;"></div>

<div id="btn" style="background-color: red; width: 50px;height: 50px;"></div>

<div id="box-text"></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2020-04-29
@sokol1111

$('#btn').click(function() {
    let background_color = $('#box1').css('background-color');
    $("#box-text").text(background_color);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question