htmlhtml-inputhtml-title

HTML input tag: how to have lots of text for title attribute?


Question

What is the best way to have lots of text for the title attribute within the HTML input type button?

Currently I literally just have lots of text, but this results in very long lines of HTML code. For example:

<input id="DoSomething" type="button" name="DoSomething" value="Do Something" title="This a shadow of the amount of text one can put as the title.">

My Use Case

Why use lots of text for the title attribute? Because I'm trying to have instructions about the button's purpose within a tooltip. My webpage is crowded, and I don't want to list the text as a paragraph, external to the button. I am open to other ideas.

Source: https://stackoverflow.com/a/2238299/11163122


Solution

  • So, this could either be done with Javascript, as follows:

    var inputDoSomething = document.getElementById('DoSomething');
    inputDoSomething.setAttribute('title', 'This a shadow of the amount of text one can put as the title.');
    <input id="DoSomething" type="button" name="DoSomething" value="Do Something">

    Or via your backend file (I am assuming C#), like so:

    C#

    protected void Page_Load(object sender, EventArgs e)
    {
      DoSomething.Attributes.Add("title","This a shadow of the amount of text one can put as the title.");
    }
    

    HTML in .ASPX file

    <input id="DoSomething" type="button" name="DoSomething" value="Do Something" runat="server">