0

I am trying to get the text/value of my cell.

My table looks somewhat like this:

    <table id="tablef" class="table table-striped">
    </table>

And i insert rows via insertRow(-1)

    var table = document.getElementById("tablev");
    var row = table.insertRow(-1);
    var cell = row.insertCell(0);
    var button = row.insertCell(1);
    cell.innerHTML = "\<center\>" + name + "\<\/center\>";
    cell.id = "cell" + i;
    var cellbutton = "\<input id='button" + i + "' type='button'value=\'Entfernen\' class='btn btn-link' >";
    button.innerHTML = "\<center\>" + cellbutton + "\<\/center\>";

I do know the cell id, but i cant figure out how to get the data that is in the cell

i tried : var cellValue = $(cellID).innerHTML; but that just gives me "undefined"

em-rg-ncy
  • 96
  • 9

1 Answers1

4

innerHTML is not part of the jQuery API, you need to use html() instead, to get text and tags, or text() if you only want the text.

Try $(cellID).html() instead.

innerHTML works on the native Element which you could access via $(cellID)[0]

GillesC
  • 10,647
  • 3
  • 40
  • 55
  • Instead of [0], you should do everything in the jQuery way. Try $(cellID).get(0).innerHTML. Of course, better would be to just $(cellID).html() – dresende Dec 05 '16 at 16:53
  • Well, i tried that aswell but that wont work neither, still get "undefined" – em-rg-ncy Dec 05 '16 at 16:54
  • If it doesn't work you're probably not triggering that code at the right moment, the element with id of cellID would need to be available on the document. – GillesC Dec 05 '16 at 16:56
  • @GiIlesC am getting data form sql via ajax and then create rows and cells with that data first cell = text second cell = button, however after all entries are created i bind an click function to the button on each row wich then tries to alert the text from cell one. all of that happens after document.ready – em-rg-ncy Dec 05 '16 at 17:03