Failed to access the opening inside the li element?

I am making a simple web application. In one part of it I:

<ul class="sortable list-group">
  <li id="firstTag" class="tags list-group-item">
    <span id="present-count" class="badge"></span>
  </li>

I need to access the li element with id = "firstTag" and the span element with id = "present-count".

Anyway, I can access only one thing, if I remove id = "firstTag", I can easily cover the range, anyway, in the presence of its js it gives an error: "it is impossible to set the property" innerHTML "null" for the operator:

document.getElementById("present-count").innerHTML = something;

EDIT:

Both are called in the window.onload function with "firstTag" called before "present-count". See this script: http://jsfiddle.net/poddarrishabh/2xzX6/3/

This is what I want the result to look like this:

enter image description here

"Present", ( bootstrap).

+4
5

present-count, li:

<ul class="sortable list-group">
   <li id="firstTag" class="tags list-group-item">
       <span id="another-tag"></span>
       <span id="present-count" class="badge"></span>
   </li>

 document.getElementById("another-tag").innerHTML = "some text";
 document.getElementById("present-count").innerHTML = "some more text";
+4
    $("#firstTag #present-count").html();

jquery

+5

, node:

var textNode = document.createTextNode("first");
document.getElementById("firstTag").appendChild(textNode);
document.getElementById("present-count").innerHTML = "something";

:

var textNode = document.createTextNode("first");
var present = document.getElementById("present-count");
present.innerHTML = "something";
document.getElementById("firstTag").insertBefore(textNode, present);

.

+5

document.getElementById("firstTag").innerHTML = document
                                                   .getElementById("firstTag")
                                                   .innerHTML 
                                              + "first";

document.getElementById("present-count").innerHTML ="something";

, .

+3

document.getElementById("firstTag").innerHTML ='<span id="present-count" class="badge">' 
                                              + '</span>' 
                                              + ' first';

document.getElementById("present-count").innerHTML = 'something';

DEMO

,

document.getElementById("firstTag").innerHTML = "first"

<span>, DOM

<ul class="sortable list-group">
    <li id="firstTag" class="tags list-group-item">
        first
    </li>
</ul>

id present-count, .

+3

All Articles