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

366
Views
Hide button if text found on page, but not if this text is also found on page

I have this working code which hides the "next" button on my checkout if customers have 'session 1 of 5', '2 of 5', '3 of 5' or '4 of 5'in their basket. Because I need them to add all 5 sessions to their basket before they can click "next"

How do I modify the code for it to also check if the page contains 'session 5 of 5' and therefore don't add class "hideElement"

Is it also possible to make this code run every couple of seconds continuously as they're navigating around a checkout system?

var itemCode = ["session 1 of 5", "session 2 of 5", "session 3 of 5", "session 4 of 5"];

var contains = itemCode.some(function(code) {
  return $(".bookly-cart-step").text().indexOf(code) >= 0;
});

if (contains) {
  $(".bookly-next-step").addClass("hideElement");
}

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

0

This is usually something you would integrate with the basket logic directly but it looks like you are using a plugin so I'm going to guess this isn't possible in your specific case, hence your question.

The below snippet will give you an idea how you could check that all sessions are present using the every array method and disable/enable the submit button accordingly (by comparing against text content in a similar fashion as your original script).

Although I wouldn't advise checking against the text contents if you can check against the basket directly.

const sessions = ['session 1', 'session 2', 'session 3']
const searchTarget = document.querySelector('.target');
const submitButton = document.querySelector('.submit')

if (searchTarget.textContent.includes('session')) {
  if (!sessions.every((session) => searchTarget.textContent.includes(session))) {
    submitButton.setAttribute("disabled", "")
  } else {
    submitButton.removeAttribute('disabled')
  }
}
<div class="target">session 1</div>
<button class="submit">test</button>

In terms of adding re-checking, you would be better off just calling the check function when a user completes a cart related action, you could use an event listener for this.

If this isn't possible you could use the mutation observer to check for the text changes, or use setInterval as a last resort since this could begin to impact performance.

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!