javascript - Get an specific value of css class, using d3js -


i have html table , want set color of specific part of table (border-top-color of cell classed "first"). color need access specific value within css class.

example:

table

<table class="tabla">     <caption>title</caption>       <tr>         <td class="first">a</td>         <td class="first">157</td>       </tr> </table>  

css class need able color

.color { fill: #95ccee;          background-color: #95ccee;          } 

to achieve, i'm using d3.js in follow way

var selecttablas = d3.selectall (".tabla");     selecttablas.selectall(".first")                 .style("border-top-color", "here function color"); 

the function should loop dataset and, depending of "d", different values of different classes.

here, extended code

http://jsfiddle.net/ploscri/dhycd/

thanks in advance.

ok here's first stab @ it. question isn't super clear, function provides way pass class name , retrieve color on class. updated example color have in question. assume have function somewhere else maps difference value classname.

http://jsfiddle.net/dhycd/1/

first thing did here make container of hidden classes carry colors testing. in order grab value css, needs present in html, assume somewhere. if it's not have no idea why you'd doing way rather defining color in javascript.

<div id='colors'>     <span class='color1'></span> </div> 

next, added css declaration have in question not in jsfiddle, changed out fill , background-color color. made sure div containing colors hidden wouldn't interfere example.

#colors { display: none } #colors .color1 { color: #95ccee } 

finally, function color class simple. code reproduced below:

function get_color(classname){     var el = document.queryselector('#colors .' + classname);     return getcomputedstyle(el).getpropertyvalue('color'); } 

this function grabs element based on class name provide argument, grabs css value of color. can see easy swap out color if wanted property value, or add property value second argument function, didn't see need in example.

hope helps, , if isn't quite after, apologize, question little difficult interpret. feel free add comment or edit clarify question , i'll update answer closer after (if didn't nail time).

edit

op clarified looking best way store color values , figured in css. not best way store color values, , recommend storing them in object in javascript, since needed in javascript. here updated fiddle stores colors in better way:

http://jsfiddle.net/dhycd/2/

if change colors.blue colors.red you'll see can swap between different colors, , syntax native javascript anyway.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -