SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    391
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Cant target class after append

    Hi,

    I am having problems targeting a class from a div i have appended inside on on click function. I have posted a section of this function below. After i have appended the html should i be able to target it from this same on click function or do i need to do something different for this?

    Thanks!

    Code:
    $(".basketButton2").on("click", function() {
    
       $(".basketList").append('<li class="basketListProduct2"><span class="productPrice2">0</span></li>'});
    
        var newProductPrice = parseFloat(oldProductPrice) + parseFloat(v['productPrice']);
        $(".productPrice2").text(newProductPrice);
    
    });

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,402
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi Banana Man,

    You've got a small typo in your code.. there's a stray curly brace at the end of this line:

    Code JavaScript:
    $(".basketList").append('<li class="basketListProduct2"><span class="productPrice2">0</span></li>'});

  3. #3
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    391
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks. For clarity I just added part of the function here and made the error during the process. Any have an idea why I'm getting this issue?

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,402
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    There shouldn't be any problem in selecting a dynamically inserted element. What's happening to the value in <span class="productPrice2">0</span> is it staying the same or being blanked or anything? Also, are you getting any errors in the browser's console?


Bookmarks

Posting Permissions

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