Reputation: 141
I'm trying to refresh a div using jQuery, but after refreshing my CSS doesn't work.
FYI : I dynamically set CSS,
document.getElementById("sai").style.color = "green";
window.setInterval('refresh()', 1000);
function refresh() {
$('#nav-tabContent').load(' #nav-tabContent')
}
After refreshing the div, green is not used.
Upvotes: 1
Views: 1170
Reputation: 125
When you add color like this:
document.getElementById("sai").style.color = "green";
you add it as an inline style.
When you rerender the div again, the inline styles that you add dynamically disappears. You should add the color
again after this action like below:
window.setInterval('refresh()', 1000);
function refresh() {
$('#nav-tabContent').load(' #nav-tabContent');
document.getElementById("sai").style.color = "green";
}
Upvotes: 2
Reputation: 41
It should be written this way. The link for the working code is here.
window.setInterval('refresh()', 1000);
function refresh() {
$('#nav-tabContent').load(' #nav-tabContent')
}
document.getElementById("sai").style.color = "green";
Upvotes: 0
Reputation: 377
You should apply the CSS style again after the refresh as it is dynamically applied. When you refresh the div, the browser will render it again with the code it contains statically and that is why the dynamically added css will not be applied.
Upvotes: 0