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

239
Views
Hide div if another div contains a specific word

I am trying to hide a div if another div contains a specific word.

This is my HTML

<div class="dynamic">
  This text is hidden if another div contains the word "download"
</div>
<div class="something">
  <div class="btn-download">
  If this text has the word "download" the div with class "dynmaic" is hidden
  </div>
</div>

JS

jQuery(document).ready(function($){
if ( $('.btn-download').text() === 'download' ) {
  $('.dynamic').hide();
}
});

What am I doing wrong? And do I need jQuery for it?

JSFiddle

many many thanks in advance

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

0

If a text in div contain a specific word you can use includes method on string ($(selector).text().includes('your-text-search'))

if ( $('.btn-download').text().includes('download') ) {
  $('.dynamic').hide();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="dynamic">
  This text is hidden if another div contains the word "download"
</div>
<div class="something">
  <div class="btn-download">
  If this text has the word "download" the div with class "dynmaic" is hidden
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

This can help, I'm not an expert but try to edit.

$(document).ready(function() {
  $("#dynamic").click(function() {
    var res = $('#dynamic').text();
    if (res == "value") {
      var hide = document.getElementById("something");
      hide.style.display = "none";
    }
  });
});
about 4 years ago · Juan Pablo Isaza Report

0

Your example code needs jQuery. This is a solution using ECMAScript 5 or older and jQuery.

jQuery(document).ready(function($){
  if ( $('.btn-download').text().indexOf('download') !== -1) {
    $('.dynamic').hide();
  }
});

Please check the fiddle https://jsfiddle.net/1sx39q6h/

For jQuery + ECMAScript 6, you have the solution of @jeremy-denis.

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!