Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

68
Views
Hide section when there's no messages to display

I need to hide the div when there are no messages to display, Javascript is used to display the messages. I have tried solutions to similar questions with no success.

HTML:

 <div class="msgList">
    <section id="messages">
        <h2>Messages</h2>
        <ul id="users-messages">

        </ul>
    </section>
</div>

JavaScript:

// Display messages in list
const messageSection = document.getElementById('messages');
const messageList = messageSection.children[1];
const newMessage = document.createElement('li');
newMessage.classList.add('msg-List');
newMessage.innerHTML = `<a href="mailto:${user_email.value}">${user_name.value}</a>. 
<span id="msg-span"> wrote: ${user_message.value}</span>`;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use conditional for user_message.value. You add the style of display none to your message section if user_message.value is null or empty.

Otherway is you can set the innerHTML as an empty string if there is no message.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!