How do I add an object to a specific position of an array?
I got an array like defined by this:
var liList = $(".paging li");
This works, and is filled with the following two items.
<li>Previous</li>
<li>Next</li>
I want to fill it with JQuery or JavaScript like the following:
<li>Previous</a></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>Next</li>
I'm currently using the following:
for (var i = 1; i < ceil; i++){
var liItem = $('<li/>')
.text(i)
.appendTo(liList);
}
This doesn't work, and returns the following HTML:
<ul class="paging">
<li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</li>
<li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</li>
</ul>
How do I do this?
Edit: I also tried something like this, but it didn't work either.
for (var I = 0; i < ceil; i++){
var liding = "<li>" + i + "</li>"
liList.splice(i, 0, liding);
}
Another edit: Using this:
for (var i = 1; i < ceil; i++){
var liItem = $('<li/>')
.text(i)
.appendTo(".paging"); // or .paging
}
returns the following:
<ul class="paginering">
<li>Previous</li>
<li>Next</li>
<li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li>
</ul>
<a>elements.<a>elements