-2

I have the text New Delhi under h2 in the HTML.

<div class="col-md-12 col-sm-12 col-xs-12 no-boot-pad">
   <h2 class="head-travel-city">Abu Dhabi to New Delhi</h2>
</div>

The querySelector for above h2 is below. I want to run a condition, if the following querySelector has the text New Delhi in it,

document.querySelector("#flight-details-container > div:nth-child(1) >
       div.row.no-boot-md-mar > div > h2")

Then hide the following querySelector container.

document.querySelector("body > div:nth-child(32) > 
div.fade.ssh-modal.ssr-modal.in.modal > div > div > div.modal-body > 
form > div.pax-row.adult > div:nth-child(3) > div")
Tibebes. M
  • 6,940
  • 5
  • 15
  • 36
Ayaz Moeen
  • 41
  • 9
  • Please always add your attempted solution(s); do not simply state your problem and await for someone else to solve it. This will help you receive more answers and avoid down-votes. – secan Oct 19 '20 at 10:56
  • Yes I understand but I am really a newbie to the JS. can't really explain things sometimes – Ayaz Moeen Oct 19 '20 at 11:22
  • that is a further reason to try; if you force yourself to explain what you already tried, you will have to think about the logic behind your code, which has two great effects: (1) you are more likely to identify by yourself where the problem is (and maybe even what the soultion could be) and (2) you get a better understanding on why your code works the way it does. Good luck with your learning journey. ;) – secan Oct 19 '20 at 12:35
  • 1
    @secan, yes that makes sense, thanks for the encouragement :) – Ayaz Moeen Oct 22 '20 at 06:28

1 Answers1

0

I assume you have multiple elements with class ".head-travel-city".

let criteria = "New Delhi"

let cities = document.querySelectorAll(".head-travel-city");
[...cities].forEach(city => {
  if (city.innerText.contains(criteria)) {
    document.querySelector("give a proper selector as I did, your way is not good").style.display = "none";
  }
})

Bulent
  • 3,307
  • 1
  • 14
  • 22