Dynamic jQuery Button Animation

Can anyone help me troubleshoot why this jQuery function isn't working on my animated button? Here are the code snippets:

HTML

<button class="btn-rounded">Button</butto>

CSS

.btn-rounded{
    color: black;
    opacidity:.7;
    border-radius:150px;
    background-color:#FFF067;
}

JS

$("#img").addClass("animated bounce");

Answer №1

It seems like your JavaScript code is not correctly targeting the button element, but rather an element with the ID #img. Additionally, the classes are being added to the element as soon as the page loads, regardless of any user action.

In order to trigger the button animation when clicked, you will need to create an event handler that applies the necessary classes to the button upon click.

$('button.btn-rounded').on('click', function(){
    $(this).addClass('animated bounce');
});

Answer №2

Forget about jQuery and opt for classic vanilla CSS instead.

.btn-rounded {
  color: black;
  opacity: 0.7;
  border-radius: 150px;
  background-color: #FFF067;
  transform: translateY(0);
  transition: transform .5s cubic-bezier(0.5, -2.5, 0.5, 3.5);
}

.btn-rounded:hover {
  transform: translateY(-25%);
}

Hover over the button to see it bounce in action. Remember to correct the opacity mistake in your CSS and the typo in the HTML code for the button.

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

Querying MongoDB to retrieve particular elements from an array within a collection

Results collection contains the following data. _id "9FK5k755ueAYdfip3" createdAt Date {Sat Mar 12 2016 19:58:46 GMT+0100 (CET)} results [Object { errorId="uX6byeiuGjRNXTj6s", error="02/09/15 13:01:29 backu...ox fil ...

Is there any HTML code that is able to implement a currency format identical to the one we've customized in Google Sheets/Google Apps Script

I am currently working with a Google Sheet table that consists of 2 columns. The second column contains charges which can vary based on user input through a Google Form and are summed up using GAS. To view an example, click here. The data from this Googl ...

Deleting content from cells in table for all even td items

This problem has been causing me frustration; I've attempted various methods using jquery and CSS, but to no avail. Essentially, I have the following table structure: <table id="mainTable"> <thead> <tr> <th>Arrival ...

Tips for showing a prompt when a user is unable to access the file

Working on a project involving PHP, HTML, and JavaScript. I am currently exploring different options for enabling users to download files. One option is to use a traditional href link that connects with the backend PHP application to initiate the file dow ...

What is the best way to organize an Express application that handles both API requests and views?

Currently, I am in the process of developing a small application that will function as both a website and its API. To achieve this, I am utilizing Node, Express, and Webpack. The structure of my directory is organized as follows: >client |>dist ...

Function not being called when the button is clicked

Here is the code for my button: <button onclick="submitFunction()">Submit</button> This is how my function is defined: function submitFunction() { alert("test"); } I have tried different solutions found online, but none of them seem to ...

Ways to determine if a website element is hidden from view

I am currently investigating the visibility of the following element: <ul class = 'pagination-buttons no-bullets'> https://i.sstatic.net/oOo7S.png When <ul class = 'pagination-buttons no-bullets'> is visible, its parent el ...

I'm seeking guidance on how to delete a specific ul li element by its id after making an ajax request to delete a corresponding row in MySQL database. I'm unsure about the correct placement for the jQuery

I have created an app that displays a list of income items. Each item is contained within an li element with a unique id, along with the item description and a small trash icon. Currently, I have implemented code that triggers an AJAX call when the user cl ...

Is there a comparable feature in AngularJS to jQuery's ajaxSuccess?

Currently, I am in the process of transitioning a jQuery module to AngularJS. Within the module, there are ajaxSuccess and ajaxError handlers that handle ajax response processing globally. These handlers are crucial for displaying success or failure messa ...

I'm having trouble with my TypeScript type declaration file not functioning properly

After trying to publish my first TypeScript NPM package and encountering issues with type recognition in my Node.js project, I realized that the type files for my package were not functioning properly. While my project structure includes files like "easyer ...

I wish to input a continuous flow of information from a JavaScript file into an HTML text box

Being an absolute beginner in the coding world, I recently attempted to create an app for a Tizen device (Samsung Gear S) that could read and display heart rate data. Initially, I utilized templates and tried writing data to the filesystem but faced some c ...

Ways to verify browser rollover support (as some mobile devices lack a cursor)

I am currently exploring options to determine if rollover events are supported for navigation. If not, I plan to switch to click events. I have reviewed jQuery.Support and Modernizr but haven't come across anything that directly addresses my issue. T ...

AngularJS provides a way to create opening pages with clickable buttons for a

I'm struggling to implement buttons that switch ons-templates when clicked. I've been following this example as a reference: Here's the code snippet I've been working on, but it just won't cooperate: <!doctype html> &l ...

Is it possible to attach a CSS file specifically to just one React component?

Is there a way to restrict the CSS styling in my Home.js component so that it does not affect any other components? I have a separate CSS file for each component, but when I apply the styling from one file to Home.js, it ends up affecting everything else ...

In JavaScript, the clearTimeout function may not always return a

Could someone please help me troubleshoot the issue in my code snippet below? I am trying to declare a public variable and assign it to a setTimeout function. If the variable is not null, I want to clear the timeout before setting it again. However, when ...

instructions on how to eliminate slideUp using jquery

I am trying to eliminate the slide-up function from my code $( document ).ready(function() { $("#tabBar ul.buttons > li > a").on("click", function(e){ //if submenu is hidden, does not have active class if(!$(this).hasClass("activ ...

Utilizing CSS property { white-space: nowrap } in Outlook for better formatting

Currently I am facing an issue with column widths in a report that I am generating dynamically and emailing directly out of SQL. The HTML for the report is being generated dynamically but there seems to be a problem with the column widths. I have added th ...

Is it possible to incorporate custom CSS, jQuery plugins, and HTML into my markdown file?

As I delve into the world of markdown for note-taking, I find myself struggling with limitations in terms of styling and making my notes visually appealing. One thing I would like to do is add warning or info style blocks using Bootstrap CSS. How can I ach ...

Can you please recommend some resources that showcase dynamic table editing using jqGrid?

Trying to navigate through the documentation found at can be overwhelming for someone new to this. I am looking for a straightforward way to retrieve data from a database, present it in a table format, allow for editing, and then save any changes back to ...

Is the flowplayer software free for use on a production server?

Here is the URL I am implementing to stream videos on my website: I would like to know if it is permissible and cost-free to use in a production environment. ...