jquery var and $(var).css -
i have code:
$(document).ready(function() { $('.fa-crosshairs').click(function() { $('*').click(function() { var currentclass = $(this).attr('class'); }); }); $('#1color').click(function() { $('body').css({ "background-color": "black" }); }); });
i need currentclass var, use instead of $('body').css, dont know how have it.
the point 1 element clicking, , then, change css when click on ('#1color')
declare variable globally.
here's example of how this.
$(document).ready(function() { var elem; $('.fa-crosshairs').click(function() { elem = this; }); $('input').click(function() { $( elem).css({ "background-color": "teal", "color": "white" }); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="fa-crosshairs">one</div> <div class="fa-crosshairs">two</div> <div class="fa-crosshairs">three</div> <div class="fa-crosshairs">four</div> <div class="fa-crosshairs">five</div> <div class="fa-crosshairs">six</div> <input type="button" value="change" />
Comments
Post a Comment