-2

I am sorting li through an array. I have figured out a working way with innerHTML, but I dont want to use innerHTML, how can I fix this without innerhtml? It works fine by now, I just want to use something else instead of .innerHTML. jQuery solution would be ideal!

ul = document.getElementById("myUL");
var lis = ul.getElementsByTagName("LI");

a.sort();//array that needs to be sorted 

for(var i = 0, l = lis.length; i < l; i++)
{ 
    lis[i].innerHTML = a[i][0]+" "+a[i][1];
}

I want to change the lis[i].innerHTML to something else in jQuery.

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
toppen
  • 71
  • 1
  • 13
  • 1
    `I just want to use something else instead of .innerHTML` Why that??? Now see jQuery `html()` method but doesn't really make sense here – A. Wolff Jul 03 '15 at 17:32
  • 1
    There is [`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) and [`appendChild`](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild) & [`createTextNode`](https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode) depending on your needs and browser support, without the use of jQuery. – Xotic750 Jul 03 '15 at 17:34
  • You can use `.text()` method in jQuery. This will only get the text inside the tags. – Michelangelo Jul 03 '15 at 17:38
  • 1
    What are contents of array `a` ? – guest271314 Jul 03 '15 at 17:41
  • I simply forgot to put paranthesis when I tried with jQuery, thats why it didn't work... now it works! Thank you everyone! – toppen Jul 03 '15 at 17:48

3 Answers3

1

.html in JQuery

$(lis[i]).html("this is how i work in jQuery");
Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
0

Use $( "div.demo-container" ).html("your html");

See : .html()

Pobe
  • 364
  • 3
  • 13
0

change

lis[i].innerHTML = a[i][0]+" "+a[i][1]

to

$(lis[i]).html(a[i][0]+" "+a[i][1])

to jQuerify it

omikes
  • 8,064
  • 8
  • 37
  • 50