Modify the class of the dropdown and heading 2 elements if they meet specific conditions using Animate.css

Is it possible to add a class using jQuery when two specific conditions are met?

1) If the dropdown selection is either "acting" or "backstage"

2) If the membership status is set to "Non-member"

If both of these requirements are fulfilled, I would like to apply an animation to the Upgrade button by adding the Animate.css class.

I have some parts of a function ready, but struggling to combine them effectively:

($(this).val() == 'Acting' || $(this).val() == 'Backstage')

and

$("#member_status").each(function() {
  var value = $(this).text();
  if(value === 'Non-member'){
  $("#upgrade_member").css('display','block');
  }
});

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
  </head>

  <body>
    <h1 id="member_welcome">Welcome to our membership site</h1>
    <h2 id="member_status">Non-member</h2>

    <select class="regular-text" name="interest" id="interest">
                <option value="not specified">Not Specified</option>
                <option value="Watching">Watching</option>
                <option value="Acting">Acting</option>
                <option value="Backstage">Backstage</option>
                <option value="Supplier">Supplier</option>
        </select>

    <div style="margin-top:20px">
    <button id="upgrade_member">Upgrade Membership</button>
    </div>

    <div id="example" class="animated infinite bounce" style="margin-top:100px;">EXAMPLE</div>
  </body>

</html>

Here is the Plunker link

Answer №1

Here's my approach:

$("#interest").change(function() {
  var memberType = $("#member_status").text().toLowerCase().includes("non-member");
  var interestValue = $("#interest").val().toLowerCase();
  if (memberType && (interestValue == "acting" || interestValue == "backstage")) {
    $("#upgrade_member").addClass("animated infinite pulse");
  } else {
    $("#upgrade_member").removeClass("animated infinite pulse");
  }
});

$(document).ready(function(){
  $("#interest").change();
});

Check out the JSFiddle demo

Answer №2

Add a specific class to your Non-member element. For instance,

<h2 id="member_status" class="myClass">Non-member</h2>

When using JQuery,

(document).ready(function () {
 function checkMembership()
  {
   var text = $('#interest :selected').text();
   If(text == "Acting" || text == "Backstage")
      {
       $(".myClass").each(function() {
       var value = $(this).text();
       if(value === 'Non-member'){
          //perform desired actions here
       }
   }
 }}})

Call the function on dropdown change event

$("#interest").change(function () {
    checkMembership();
});

If this solution works for you, kindly mark it as the answer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Proper Techniques for Removing, Creating, and Storing Referenced Data in Mongoose and Express

The main issue I am facing is that when attempting to delete a Comment, I am unable to locate the index of that specific comment within the post.comments and user.comments arrays as it consistently returns -1. The reason I need to find it is so that I can ...

Flask web framework fails to deliver Jquery ajax json get call

I've been attempting to make a simple jQuery AJAX call to fetch JSON data, but I'm running into issues and struggling to understand why. Below is the code. It appears correct to me. $(document).ready(function() { function onDataReceived (d ...

Injecting a controller into an AngularJS module within an anonymous function

As a newcomer to the world of javascript and just beginning to work with angular.js, I have a question. I'm wondering if there is a method for injecting a controller into a module that is declared within an anonymous function. This is how my code cu ...

Issue with highcharts and vue.js: creating a unique chart for displaying measurements

Currently, I am integrating Highcharts and Vue.js simultaneously while incorporating multiple charts on my webpage. As of now, I have successfully displayed data on all the charts without encountering any issues. However, my goal is to assign a special tit ...

Dropdown Pattern with React CTA Modal

While using MaterialUI's ButtonGroup for a dropdown menu, I encountered an issue trying to set up a series of CTAs that are easily interchangeable within it. The goal is to have all components reusable and the choices in the dropdown dynamic. const C ...

Issue with executing callback function in ajax form

I am having an issue with submitting a form using AJAX to a servlet. The form is being submitted successfully, the database entries are changing, but for some reason the callback function is not executing. Any help would be greatly appreciated. Here is the ...

Is it possible to utilize v-html with message data in Vue without any limitations on the <title> element?

Currently utilizing Vue.js 2 and my SDK is IntelliJ: I am attempting to bring HTML content into a Vue.js file. The main objective is to include the <title></title> attribute, as it seems that Vue doesn't have direct support for this feat ...

Stop automatic scrolling when the keyboard is visible in Angular

I have created a survey form where the user's name appears on top in mobile view. However, I am facing an issue with auto scroll when the keyboard pops up. I want to disable this feature to improve the user experience. <input (click)="onFocusI ...

Utilizing ng For in a personalized directive to fill a selection menu

I encountered an issue while trying to populate a selected dropdown using ngRepeat inside a custom directive. I came across this example that seemed similar to what I wanted to achieve here. Although it worked for the example, it didn't work for me. ...

Utilize getJSON to refresh the JavaScript datetimepicker

I am currently using an api with ajax (getJSON) to append data to a specific div called 'open' on my website. However, I now want to update the static values in my datetime picker script for minTime and maxTime. Here is the code snippet: AJAX ...

merging pictures using angular 4

Is there a way in Angular to merge two images together, like combining images 1 and 2 to create image 3 as shown in this demonstration? View the demo image ...

Looking to validate each input field individually using jQuery?

I am in need of validating all form inputs in the keyup function without having to write validation for each individual input. Is there a way to achieve this using methods like each();? Apologies for what may seem like a silly question. ' ...

Is there a way to track when the Angular DTOptionsBuilder ajax call is complete and trigger a callback function?

Working with angular datatables, I have the following code: beforeSend:</p> success callback causes the table on the page not to populate with the data. How can I implement a callback that triggers once the ajax is done without interfering with the ...

What is the best way to create a view that caters to both administrators and regular users?

Currently, I am developing a system in Django which displays different fields and options based on whether the user is an administrator or a Jefe from the table. The administrator can access the panel in Django. class UsuarioCrear(SuccessMessageMixin, Crea ...

Learning how to integrate Next.js, React.js, and Redux into an HTML page for an enhanced user

My current project is built on Asp.Net MVC, but the technology used is not crucial. I integrated react.js and redux for searching a section of my html page using a cdn link. Now, I am considering deploying the server side of the application with next.js. ...

information not visible on the webpage

Recently, I made an alarming discovery on my website. I have implemented two different types of menus - one for the front page (designated as .navbar-inverse) and another for all other pages (.navbar-default). The front page menu is static while the other ...

Bulma: Tips for creating equally sized buttons?

I am working with Bulma CSS and trying to ensure that all my buttons are the same size. Currently, each button appears to have a different size based on the text content. I have looked into using the "is-fullwidth" option, but it makes the buttons too la ...

Struggling with converting 11-line toy neural network code into JavaScript

I'm preparing to deliver a brief presentation on neural networks this coming Tuesday to my fellow web developer students. My plan was to convert this code (found under Part 1, a tiny toy neural network: 2 layer network) into JavaScript so that it woul ...

Show users who liked a post from 2 different collections in Meteor

How do I retrieve a list of users who have "liked" this post from a collection and display it in a template? Collections: likes: { "_id": 1234, "userId": "1dsaf8sd2", "postId": "123445" }, { "_id": 1235, "userId": "23f4g4e4", "pos ...

Article discussing the Facebook like button

I've recently incorporated Facebook like buttons into the articles on my online store. It's great because when someone shares a post about a product or article, it shows up on their wall. Users receive notifications on Facebook when someone else ...