0

I have a toggle link to show or hide a table. This is the code for the link. When this is shown there is no blank line between the link and the table underneath

<a id='togglelink' name='togglelink' href='javascript:ToggleTable();' title='Show Inactive EDB Appointments' >
    <p style='text-align:center'>Show Inactive EDB Appointments
</a>

When the link is clicked a table is shows and I change the link text

link.innerHTML = "<P style='TEXT-ALIGN: center'>Hide Inactive EDB Appointments";

After this code is executed a blank line appears between the link and the table underneath

user1345246
  • 135
  • 1
  • 9

3 Answers3

0

You forgot to close the <p> tag.

link.innerHTML = "<p style='text-align: center'>Hide Inactive EDB Appointments</p>";

alexandreferris
  • 662
  • 1
  • 11
  • 29
0

Close off the paragraph tag within the HTML and the JavaScript.

<a id='togglelink' name='togglelink' href='javascript:ToggleTable();' title='Show Inactive EDB Appointments' >
    <p style='text-align:center'>Show Inactive EDB Appointments</p>
</a>

link.innerHTML = "<p style='text-align: center'>Hide Inactive EDB Appointments</p>";
Ash
  • 2,108
  • 2
  • 17
  • 22
0

Instead of using href="javascript: [some code]", which does not work in all browsers, you should use an onclick attribute as below and demo'd in this fiddle

<a id='togglelink' name='togglelink' href='#' title='Show Inactive EDB Appointments' onclick="ToggleTable();">
     <p style='text-align:center'>Show Inactive EDB Appointments
     </p><!-- Added in closing tag -->
</a>

Notes:

  1. I made sure to close the <p> tag, though this was not the problem.
  2. I've provided an example ToggleTable() function that guesses at how you initialize var link. I'd recommend document.getElementById('togglelink') or $('#togglelink') if using jQuery.
  3. An alternative to the onclick attribute, as commented in the fiddle, is an event listener. Example below, if using jQuery:
function ToggleTable() {
    var link = document.getElementById("togglelink");
    link.innerHTML = "<P style='TEXT-ALIGN: center'>Hide Inactive EDB Appointments</p>";
}

$(document).on("click tap","#togglelink",function() {
    ToggleTable();
});
sqsinger
  • 500
  • 1
  • 3
  • 13