J. Doe J. Doe -4 years ago 173
jQuery Question

OnClick change color from another element

I currently have this code

$('well').click(function () {
$('span').css('background-color', '#000').css('color', '#000');

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download