Kwasi Denkyira

Kwasi Denkyira

  • 1.8k
  • 98
  • 4.2k

Get the value inside element give me double \n in empty case

Dec 7 2019 6:24 AM
I am using MVC 5 and html table to render a view. In one of the table cell, I want to check if the value inside the td tag is null or not and show or hide an item using JQuery. I am using the code below but for some reasons the value inside the tag is showing "\n \n" and therefore always not null. I have included a screen and my code. Any help to remove "\n \n" so I can check if the value is null or not will be appreciated.
 
 
  1. $(document).ready(function(){  
  2. $("button").click(function()  
  3. {  
  4. var v = $("#hideheader").html(); ----> This value here is showing "\n \n"  
  5. if(v=='') --- This is always not empty  
  6. {  
  7. alert('empty');  
  8. $("#hide").hide();  
  9. }  
  10. else  
  11. {  
  12. alert('non-empty value');  
  13. }  
  14. });  
  15. });  
  16. <table>  
  17. <thead><tr> <th id="hide">ID</th></tr> </thead>  
  18. <tbody><tr><td id="hideheader">@item.adminstring</td></tr></tbody>  
  19. </table>  

Answers (1)