Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  53] [ 4]  / answers: 1 / hits: 18622  / 13 Years ago, thu, february 2, 2012, 12:00:00

I'm trying to use JavaScript to create an li and append it to an existing ol. The code I am using is



<ol id=summaryOL>
</ol>

function change(txt) {
var x=document.getElementById(summaryOL);
newLI = document.createElementNS(null,li);
newText = document.createTextNode(txt);
newLI.appendChild(newText);
x.appendChild(newLI);
}

change(this is the first change);
change(this is the second change);


These should look like:



1. this is ...
2. this is ...


But look like:



this is the first changethis is the second change


I have created a fiddle at: fiddle . Thanks for any help.


More From » html-lists

 Answers
6

Here is an example - jsfiddle



$(function() {
var change = function( txt ) {
$(#summaryOL).append( '<li>' + txt + '</li>' );
};

change(this is the first change);
change(this is the second change);
});


To use jquery, put below code inside of <head></head>



<script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js></script>

[#87683] Tuesday, January 31, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jailynbethanies

Total Points: 686
Total Questions: 119
Total Answers: 99

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;