Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By sarahswansea

Thread: jquery each function not working

  1. #1
    Junior Member
    Join Date
    Jun 2015
    Location
    London
    Posts
    16
    Member #
    50439

    jquery each function not working

    I am working on this site here: Bromley and Bexley Teaching Schools Collaborative

    If you go to "Specialism > CPD", you should see two people. The first person, when you click their request button, selects their name in select box. (Good) When you select the second person it still pulls through the first persons name instead. (Bad)

    I thought i would use .each() so each profile would select the correct name from the list, but its not working.

    Could anyone tell me why this isn't working, or even suggest a better option if there is one?

    Thanks

    Here is my code for my request button:

    HTML Code:
        $(".requestBTN").each(function() {
            $(this).click(function (e) {
                e.preventDefault();
    
                var staffname = $(this).parents().find('h2').html();
                $('#staffDDL option[value="' + staffname + '"]').prop('selected', true);
    
                $('#RequestForm')
                  .css('opacity', 0)
                  .slideDown('slow')
                  .animate(
                    { opacity: 1 },
                    { queue: false, duration: 'slow' }
                  );
            });
        });

  2.  

  3. #2
    Senior Member sarahswansea's Avatar
    Join Date
    Oct 2015
    Location
    Swansea, UK
    Posts
    152
    Member #
    52184
    Liked
    64 times
    Looking at the HTML, it seems you just want to change parents to parent:

    var staffname = $(this).parent().find('h2').html();

    Also, you may not need the .each, I believe you can just do

    $(".requestBTN").click(function ...

    Hope that helps!
    Abyssalwolf and Ronald Roe like this.

  4. #3
    Junior Member
    Join Date
    Jun 2015
    Location
    London
    Posts
    16
    Member #
    50439
    Quote Originally Posted by sarahswansea View Post
    Looking at the HTML, it seems you just want to change parents to parent:

    var staffname = $(this).parent().find('h2').html();

    Also, you may not need the .each, I believe you can just do

    $(".requestBTN").click(function ...

    Hope that helps!
    OMG thanks for this Sarah, this worked! i knew i was close but didn't know i was a few characters off lol.

    Thanks again!

  5. #4
    Senior Member sarahswansea's Avatar
    Join Date
    Oct 2015
    Location
    Swansea, UK
    Posts
    152
    Member #
    52184
    Liked
    64 times
    You are very welcome and the website looks really nice by the way!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com