J. Doe J. Doe - 3 months ago 12
jQuery Question

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..

Answer

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

});
Comments