Here is the div to which I am trying to add class
<div id="sidebar" class="addthis_recommended_horizontal col-lg-4 col-md-4 col-sm-6 col-xs-12""></div>
and this is the script I am using
<script>window.onresize=function()
{var width=document.getElementById("#sidebar").clientWidth;
if(width<640) {document.getElementById("#sidebar").setAttribute("class",".sidebar");}
</script>
After adding this class, this CSS code changes the width
.sidebar.at4-recommended-item{width:45%!important}
But the class was not being added, I don't know why?
EDIT I am using media queries. In this case two classes have same name If I change one other will change too so I am adding a class dynamically, and it is a div not whole window width that I need to change.
WHY ARE PEOPLE SO KEEN ON DOWNVOTING EVERY QUESTION HERE?