html - CSS triangle changing display value with Javascript -
i have got html
<div id="slidemenu"> <div id="slidem1" onmouseover="colorm(1)">something 1</div> <div id="slidem2" onmouseover="colorm(2)">something 2</div> <div id="slidem3" onmouseover="colorm(3)">something 3</div> <div id="slidem4" onmouseover="colorm(4)">something 4</div> <div id="slidem5" onmouseover="colorm(5)">something 5</div> </div>
and css
html, body{ font-family: "century gothic", "apple gothic", applegothic, "urw gothic l", "avant garde", futura, sans-serif; } #slidemenu { float: right; } #slidem1:before, #slidem2:before, #slidem3:before, #slidem4:before, #slidem5:before { content: ""; position: absolute; top:0; right:210px; width: 0; height: 0; border-top: 32px solid transparent; border-right: 30px solid #602f4f; border-bottom: 32px solid transparent; display:none; } #slidem1, #slidem2, #slidem3, #slidem4, #slidem5 { background-color: silver; height: 54px; width: 200px; text-align: right; position:relative; padding: 5px; color: white; margin-bottom: 2px; }
and javascript
function colorm(n) { document.getelementbyid("slidem"+n).style.backgroundcolor="#602f4f"; document.getelementbyid("slidem"+n+":before").style.display="block"; }
here jsfiddle http://jsfiddle.net/xn6da/ . can see css triangle has default value display: none;
. after it's hovered want change it's value visible. tried use document.getelementbyid("slidem"+n+":before").style.display="block";
still hides triangle, how remove display: none;
css javascript?
thank you
you cannot modify pseudo classes via javascript. need change adding/removing class. instance, adding css this:
#slidem1.show:before, #slidem2.show:before, #slidem3.show:before, #slidem4.show:before, #slidem5.show:before { display: block; }
and javascript
function colorm(n) { document.getelementbyid("slidem"+n).style.backgroundcolor="#602f4f"; document.getelementbyid("slidem"+n+).classname="show"; }
here fiddle. http://jsfiddle.net/xn6da/1/
i recommend removing ids , replacing them common class. currently, every time add element. going need create id , add css.
Comments
Post a Comment