J. Doe
J. Doe

Reputation: 113

OnClick change color from another element

I currently have this code

 <script>
$('well').click(function () {
    $('span').css('background-color', '#000').css('color', '#000');
});
</script>

and I'm trying to make when I click on this "well" (from bootstrap) the color to a span from this well to be changed..

Upvotes: 1

Views: 475

Answers (1)

Akshay
Akshay

Reputation: 805

if well is class than use .well

$('.well').click(function () {
    $('span').css({backgroundColor:'#000', color:'#000'});
});

if well is id than use #well

$('#well').click(function () {
    $('span').css({backgroundColor:'#000', color:'#000'});
});

Also make sure to wrap your code in DOM ready:

jQuery(function( $ ) { // DOM is now read and ready to be manipulated and $ alias secured

   // Your $ jQuery code here

});

Upvotes: 3

Related Questions