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

257
Views
Onclick function on font awesome icon

I have 4 icons in my menu bar and when I press the fa-plus-square I want to hide the div #addPost. I believe my JS is fine and cannot locate the issue here

function showPost(){
    let add = document.getElementsById("addPost")
    if (add.style.display === "none" ){
        add.style.display = "block"
    } else {
        add.style.display = "none"
    }
}
        <ul class="icons"> 
            <li>
                <i class="fas fa-home" style="color: black;"></i>
            </li>
            <li>
                <i class="fas fa-inbox"></i>
            </li>
            <li>
                <i class="far fa-plus-square" onclick="showPost()"></i>
            </li>
            <li>
                <i class="far fa-heart"></i>
            </li>
        </ul>
        
 <div id="addPost" >
        <div class="title">Create new post
            <i class="fas fa-times"></i>
        </div>
        <div class="name">
            <input type="Name" placeholder="Username" required>
        </div>
        <div class="post">
            <textarea placeholder="What's on your mind?" ></textarea>
        </div>
        <div class="comment">
            
        </div>
    </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It should be getElementById not getElementsById! Remove the 's' at the end of element.

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!