vendredi 30 janvier 2015

Using javascript variables in .css() jQuery


Messing around with a Javascript function... It refreshes every .5 seconds to append the following css:



var pg_width = $(window).width();
var element_width = (pg_width - 20) / 2;
var element_height = element_width / 2;
$(".article_document").css({"background-color":"red", "width":""+element_width+"px", "height":""+element_height+"px"});


The red background color is appended to .article_document, although width and height are not. Is the code incorrect?



<div class='article_document'>
<img src='uploads/code0.png' class='article_image'>
<span class='article_title'>example</span>
<span class='article_author'>example</span>
<span class='article_idn'>example</span>
</div>


EDIT: Appears the issue had been my browser oddly... Thanks!





Aucun commentaire:

Enregistrer un commentaire