countdown error with getElementsByClassName

I have an error using the getElementsByClassName, it does not show me the results you want in my class. When I use an getElementbyID that works smoothly with the class but no way, I have no error in the console I do not understand why the result is not displayed.

document.getElementsByClassName('countdown_product').innerHTML = '<span class="texte_countdown" style="text-align:center;"></span><br/>';
document.getElementsByClassName('countdown_product').innerHTML += '<span class="days">'+ days+ '</span>';
document.getElementsByClassName('countdown_product').innerHTML += '<span class="hours"><span class="pts_countdown">:</span>' + hours+ '</span>';
document.getElementsByClassName('countdown_product').innerHTML += '<span class="minutes"><span class="pts_countdown">:</span>' + minutes+ '</span>';
document.getElementsByClassName('countdown_product').innerHTML += '<span class="seconds"><span class="pts_countdown">:</span>' + seconds+ '</span>';
document.getElementsByClassName('countdown_product').innerHTML += '<span class="milliseconds"><span class="pts_countdown">:</span>' + milliseconds+ ' </span>'

My fiddle


getElementsByClassName returns an array of the selected DOM Element objects, you should iterate through the selected elements and update the innerHTML for every selected element. You are adding a innerHTML property to the returned Array object which of course doesn't throw an error but doesn't do what you expect.

var elems = document.getElementsByClassName('countdown_product');
for ( var i = 0; i < elems.length; i++ ) {
   elems[i].innerHTML = '<span class="texte_countdown" style="text-align:center;">text</span>';

As you are loading jQuery you can select the elements by className and use html or append method, jQuery uses each method behind the scene and updates the innerHTML properties for you.


Need Your Help

Custom Keybindings for Ipython terminal

python keyboard-shortcuts ipython key-bindings

Is it possible to define custom keybindings and/or desactivate the default ones for Ipython terminal interface?

NSView subview right click not working over nsimageview

osx cocoa nsview right-click nsimageview

I have to two subviews associated with a view. One is a transparent view that handles a right click, the other a nsview with an nsimageview subview. For some reason the right click works over any p...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.