1

Why do I get this error in javascript: Cannot set property 'innerHTML' of null

My code:

<asp:Literal ID="topLinkArticleOut" runat="server"></asp:Literal>
<button type="button" id="deleteTopLinkArticle" name="deleteTopLinkArticle" 
onclick="ChangeText()" class="btn red" style="float: right;">Delete</button>

function ChangeText() 
{
document.getElementById("topLinkArticleOut").innerHTML = "";
} 
Mykremin
  • 23
  • 1
  • 6

1 Answers1

1

As far as I know an <asp:Literal will just output text so there won't actually be a HTML element with an ID for you to target. If you use label it will output a HTML element. However I am not sure what that asp code it doing, because it would be outputting nothing and with label it would output an empty HTML element anyway.

<asp:Label ID="topLinkArticleOut" runat="server"></asp:Label>
WizardCoder
  • 3,353
  • 9
  • 20