I have this code which shows a 'Top of the page' link when scroll down:
window.addEvent('load', function() {
new JCaption('img.caption');
});
function fade_me(num){
var smoothtop=document.id('smoothtop');
if(smoothtop){smoothtop.fade(window.getScrollTop()<250?0:num);}
}
window.addEvent('domready',function(){
var scroll=new Fx.Scroll(window,{
'duration': 500,
'transition': Fx.Transitions.Bounce.easeInOut,
'wait': false
});
var smoothtop=new Element('div',{
'id': 'smoothtop',
'class': 'smoothtop',
'style': 'position:fixed; display:block; visibility:visible; zoom:1; opacity:0; cursor:pointer; right:5px; bottom:5px;',
'title': '',
'html': '',
'events':{
mouseover: function(){fade_me(1);},
mouseout: function(){fade_me(0.7);},
click: function(){scroll.toTop();}
}
}).inject(document.body);
document.id('smoothtop').setStyle('opacity','0');
});
window.addEvent('scroll',function(){fade_me(0.7);});
//this is what I added
var ii = document.getElementById('smoothtop');
ii.childNodes[0].nodeValue = '<i class="icon icon-chevron-up"></i>';
//these two lines
As you can see the code generates a div with id smoothtop. It has a arrow-up picture to indicate the top of the page. Instead, I want to use BootStrap's glyphicon using
<i class="icon icon-chevron-up"></i>
I have tried to add this content to div smoothtop. When I inspect the code with FireBug, it says:
TypeError: ii is null
var ii = document.getElementById('smoothtop');
I couldn't figure where and/or what am I doing wrong? I want to ask how I can add <i></i> into the div which has been created by js?