html - Getting CSS data from file using jquery -
i want jquery select background-color css class isn't in document (although hover uses same color).
this code i've got @ moment:
<a id='changetext1'> <div class='tile color_red1'>text</div> </a> <a id='changetext2'> <div class='tile color_orange1'>text</div> </a> <div class='rightside color_red2' id='rightside'>some more text</div> the rightside starts off color_red2, i'd change color_orange2 on clicking color_orange1 div. , of course change color_red2 when red div being clicked.
the text , colors come sql database , put jquery json
function rightsidedata(data) { $.each(data, function(i, d) { $("#changetext" + d.id).on('click', function() { //change background color match :hover color of right div todo }); } }); the part switching text works fine, i'm stuck @ changing background-color property. color can retrieved json data (d.color), cannot figure out how .color_orange2 background-color css file.
edit: solution following:
var color = window.getcomputedstyle($(".color_"+d.color+"1").get(0),':hover').getpropertyvalue('background-color'); $('.color_red2').css("background-color",color);
you try use getcomputedstyle evaluate divs' classes. think like
var color = window.getcomputedstyle($('.color_red1').get(0),':hover').getpropertyvalue('background-color'); might possibly work...
Comments
Post a Comment