Rafael
Rafael

Reputation: 219

Change draggable background-color by pressing button

how can you change the background color of a draggable element by pressing a button(with the same background-color as the button).

I've been looking into some other posts but I still can't do It.

<div id="draggable" class="ui-widget-content">
  element1
</div>

<button id="colorbtn" onclick="changeColor(#66FF66)" style="background-color: #66FF66;"></button>



 $( "#draggable" ).draggable(value);
function changeColor(){
    $('#draggable').css('background-color',value);
}

Here is a fiddle of what I'm trying to do fiddle

Upvotes: 0

Views: 263

Answers (1)

Brett
Brett

Reputation: 2010

Based on your fiddle code

$( "#draggable" ).draggable();

$('#colorbtn').click(function() {
    $("#draggable").css('background', $(this).css('background-color')); 
});

seems like fiddle doesn't like setting background color. Just use background

Upvotes: 3

Related Questions