Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add css class to dynamically created div

CSS
   .horizontal {
    width: 100%;
   
    overflow: auto;
}



HTML
<div id="dvGridView" >
 <table id="tbl" > </table>
</div>


JavaScript
var str="<tr><td><div id=\"grid\"></div></td></tr>";


What I have tried:

$('#tbl').append(str);

$('#grid').addClass("horizontal");
or
$('#tbl tr').find('#grid').addClass("horizontal");
Posted
Updated 8-Mar-16 0:08am
v2
Comments
Kornfeld Eliyahu Peter 8-Mar-16 5:06am    
And what is your problem?
Look here to see that all you wrote is done... https://jsfiddle.net/zLeyve4t/
Member 7909353 8-Mar-16 5:09am    
If table (tbl) has 50 column then div(grid) should has horizontal scroll bar
Member 7909353 8-Mar-16 5:16am    
if
var str="<tr><td><div id=\"grid\"><table><thead class=\"thead-inverse\"><tr><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th><th>aaaaaa</th></tr></thead></table></div></td></tr>";

then div(id=grid) should has horizontal scroll bar.
Krunal Rohit 8-Mar-16 5:19am    
try this as your str,
var str="<tr><td><div id='grid'>lorem ipsum</div></td></tr>";


KR
Member 7909353 8-Mar-16 5:28am    
yes div has class='horizontal' but horizontal scroll bar does not show

if set $('#dvGridView').addClass("horizontal"); it is working bcoz div(dvGridView) created statically

1 solution

.horizontal {
width: 70%;

overflow: scroll;
}

$('#grid').addClass("horizontal");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900