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

178
Views
I need to hide reply-box when i press a bootstrap class button

let btn = document.getElementById('reply-button');
let crdbody = document.getElementById('card-body');
let replybox = document.getElementById('reply-box');
let cancel = document.getElementById('btn btn-danger');

btn.onclick = function() {
  replybox.style.display = "contents";
}
cancel.onclick = function() {
  crdbody.style.display = "none";
}
<button class="btn" id="reply-button">Răspunde</button>
    <div id="reply-box" class="card" style="display: none">
        <div class="card-body">
            <textarea class="form-control"></textarea>
            <br>
            <div class="form-group">
                <button class="btn btn-primary">Postează răspunsul</button>
                <button class="btn btn-danger">Renunță</button>
            </div>
        </div>
    </div>

My question is, how do i hide all replybox when i press this bootstrap class button(btn btn-danger) - renunta(cancel)

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

0

Your classes/id are errorous:

  • card-body is actually a class but youre using it as an id
  • id reply-button never appears in your html
  • id cancel-button never appears on your html
  • using document.getElementById('btn btn-danger') doesnt work you need to put an id in there, not multiple classes.

Heres your fixed code:

let btn = document.getElementById('reply-button');
let crdbody = document.getElementById('card-body');
let replybox = document.getElementById('reply-box');
let cancel = document.getElementById('cancel-button');

btn.onclick = function() {
  replybox.style.display = "contents";
}
cancel.onclick = function() {
  crdbody.style.display = "none";
}
<div id="reply-box" class="card">
  <div id="card-body">
    <textarea class="form-control"></textarea>
    <br>
    <div class="form-group">
      <button class="btn btn-primary" id="reply-button">Postează răspunsul</button>
      <button class="btn btn-danger" id="cancel-button">Renunță</button>
    </div>
  </div>
</div>

Please be aware that display: contents; is working draft css (see https://caniuse.com/?search=display%3Acontents and https://drafts.csswg.org/css-display/) which means it still may be subject to change and isnt a real standard yet, so you shouldnt (yet) rely on that feature in your actual production code.

Update since you cant change the HTML:

let btn = document.getElementById('reply-button');
let replybox = document.getElementById('reply-box');
let cancel = document.querySelector('.btn.btn-danger');

btn.onclick = function() {
  replybox.style.display = "contents";
}
cancel.onclick = function() {
  replybox.style.display = "none";
}
<button class="btn" id="reply-button">Răspunde</button>
<div id="reply-box" class="card" style="display: none">
  <div class="card-body">
    <textarea class="form-control"></textarea>
    <br>
    <div class="form-group">
      <button class="btn btn-primary">Postează răspunsul</button>
      <button class="btn btn-danger">Renunță</button> </div>
  </div>
</div>

When selecting elements by classes you can use document.querySelector (for single elements) and document.querySelectorAll (for multiple elements).

Also note that i removed the crdbody variable and changed the script to hide/show the replybox so it properly opens/closes multiple times.

about 4 years ago · Juan Pablo Isaza Report

0

Try this. You need this result?

let btn=document.querySelector('#reply-box .btn.btn-primary');
let replybox=document.getElementById('reply-box');
let cancel=document.querySelector('#reply-box .btn.btn-danger');
btn.onclick=function(){
    replybox.style.display="contents";
}
cancel.onclick=function(){
    replybox.style.display="none";
}

btn.click(); // just for testing... it displays the reply box at first time.
    <div id="reply-box" class="card" style="display: none">
        <div class="card-body">
            <textarea class="form-control"></textarea>
            <br>
            <div class="form-group">
                <button class="btn btn-primary">Postează răspunsul</button>
                <button class="btn btn-danger">Renunță</button>
            </div>
        </div>
    </div>

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!