Hide a Div Based on Another Divs Text?

I’m trying to show/hide a div in a form depending on the text contained in another div on the same form.
The code below will hide “.form-group-919” whether the other div contains the provided text or not. I’m having trouble getting it to hide if the text doesn’t match “Job Edit Allowed”.

Any ideas?

var inTerval = setInterval(function(){
if ($('.form-group-968').text() == "Job Edit Allowed") {
  $('.form-group-919').show();
}
  else
  {
    $('.form-group-919').hide();
  }
}, 250);
if ($('.form-group-968').text() == "Job Edit Allowed") {
  $('.form-group-919').show();
}

What you said in English doesn’t seem to match with what you said in your code.

Sorry, it’s late here & I probably should sleep lol. I’ve edited my post. It should hide if the text doesn’t match “Job Edit Allowed”.

I don’t see anything fundamentally wrong with your code. I used it in a quick codepen and it works fine for me. I think you are going to have to either provide us with a link to your project so we can see it running for ourselves or give us a lot more information.

What I’m building is a form to add jobs into a database. This is the full sequence for this feature.

On the form I have the following code that checks the ID of the job we’re working with. When creating a new job, the ID is always ‘0’ by default & also has default text “Job Edit Allowed”. If the ID is greater than ‘0’, it will echo/replace the default text with “Job Edit Not Allowed”.

$item_id = $_GET['item_id']; //Get job ID

if($item_id>0) //ID for new record before creation is always 0
{
  echo '<b style="color:red" <b>Job Edit Not Allowed</b>'; //output value
  }

The next step is showing or hiding the message on the form, letting the user know they cannot edit the job.

var inTerval = setInterval(function(){
	$('.form-group-968:contains("Job Edit Allowed")').hide();
	$('.form-group-968:contains("Job Edit Not Allowed")').show();
}, 250);

The last part is what I originally posted.

var inTerval = setInterval(function(){
if ($('.form-group-968').text() == 'Job Edit Allowed') {
  $('.form-group-919').show();
}
  else
  {
    $('.form-group-919').hide();
  }
}, 250);

If this isn’t enough, I could work on putting something together with a login for you.

Is there more than one element with the class .form-group-968? If so then I think that’s your problem. You’ll need to go through each of them one at a time and only adjust their particular .form-group-919.

If this isn’t the issue then I’m afraid I don’t have enough info to help you.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.