I have the following mark up code
<!DOCTYPE html> <html> <head> <title>Untitled</title> </head> <body> <table> <tr> <th></th> <th></th> <th>Back</th> </tr> <tr> <td class="runner-row runner-back">1.98</td> <td class="runner-row runner-back">1.99</td> <td class="runner-row runner-back runner-back-active">2.00</td> </tr> </table> </body> <!-- jQuery --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> </html> I use the following Javascript code to change the values of my "runner-row" elements
window.onload = function() { var gElemRunners = $(".runner-row"); gElemRunners[0].innerHTML = 1.5; gElemRunners[1].innerHTML = 1.6; gElemRunners[2].innerHTML = 1.7; } This code works absolutely fine and the values update properly when the window has loaded. However, the following code does not work.
window.onload = function() { var gElemRunners = $(".runner-row"); gElemRunners[0].html(1.5); gElemRunners[1].html(1.6); gElemRunners[2].html(1.7); } I get the following error in DevConsole
Uncaught TypeError: $(...)[0].html is not a function I get the same error even if I change the .html to .text or .val. Please help me with this because I can't seem to understand where the problem lies.
$('selection')[0]exposes the DOM API underneath. This will not return a jQuery object and therefore will not have the.html()method..eq(0).html()or you could just use the method that works already.