Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:49:43+00:00 2026-06-13T11:49:43+00:00

I am not really familiar with jQuery. I have this code that I downloaded

  • 0

I am not really familiar with jQuery. I have this code that I downloaded to create a fade in/fade out popup form. Here’s the code:

<script type='text/javascript'>
    $(document).ready(function() {
        $('#button').click(function(e) { 
            $('#modal').reveal({ 
                animation: 'fade',
                animationspeed: 150,
                closeonbackgroundclick: true, 
                dismissmodalclass: 'close'
            });
            return false;
        });
    });
</script>

The code above executes when a button with an id='button' is clicked. Now I have multiple buttons, how can I call this function in all buttons? I tried setting the id of all buttons to button but only the first button works. Any help would be very much appreciated.
By the way I forgot to mention, in my .php file i have this codes:

for ($c=1;$c<=5;$c++){
echo "<input type='button' id='button'">
};

This php code will display 5 buttons with the same id which is ‘button’. What I want to happen is when I click any of the 5 buttons the jQuery function will execute which is popping up a fade in/fade out form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:49:44+00:00Added an answer on June 13, 2026 at 11:49 am

    First solution :

    function doClick(e) { 
       $('#modal').reveal({ 
         animation: 'fade',
         animationspeed: 150,
         closeonbackgroundclick: true, 
         dismissmodalclass: 'close'
       });
       return false;
    }
    $('#button1').click(doClick);
    $('#button2').click(doClick);
    

    Second solution :

    Give a class “someClass” to all the involved buttons

    <input type=button class=someClass ...
    

    and do

    $('.someClass').click(function(e) { 
    ...
    });
    

    Third solution :

    Use the comma to separate ids :

    $('#button1, #button2').click(function(e) { 
    ...
    });
    

    Generally, the best solution is the second one : it allows you to add buttons in your code without modifying the javascript part. If you add some of those buttons dynamically, you may even do

    $(document).on('click', '.someClass', function(e) { 
    ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really not familiar with jQuery. Is there anyway I can pass form data to
I'm not really familiar with creating generic methods, so I thought I'd put this
I'm writing a java binding for a C code and I'm not really familiar
Im not really familiar with how this works in JSP but in the main.jsp
I am not really familiar with Joomla but I have been tasked with writing
I'm not really familiar with the connection protocols. I'm using the following code to
Little help please, because I am not really familiar with this kind of thing.
I'm not really familiar with Ajax Response - I have edited the PHP Ajax
I'm new here, also a novice programmer, and not really familiar with PHP. I
Let me start by saying that I'm a linux guy and not really familiar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.