JavaScript, getting value of a td with id name

后端 未结 8 1433
难免孤独
难免孤独 2020-12-01 02:53

Originally I was using input with an id and grabbing it\'s value with getElementById. Currently, I\'m playing with s. How can I grab the values of the

相关标签:
8条回答
  • 2020-12-01 03:35

    use the

    innerHTML 
    

    property and access the td using getElementById() as always.

    0 讨论(0)
  • 2020-12-01 03:36

    To get the text content

    document.getElementById ( "tdid" ).innerText
    

    or

    document.getElementById ( "tdid" ).textContent
    
    var tdElem = document.getElementById ( "tdid" );
    var tdText = tdElem.innerText | tdElem.textContent;
    

    If you can use jQuery then you can use

    $("#tdid").text();
    

    To get the HTML content

    var tdElem = document.getElementById ( "tdid" );
    var tdText = tdElem.innerHTML;
    

    in jQuery

    $("#tdid").html();
    
    0 讨论(0)
提交回复
热议问题