Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
How to get data from dynamically generated element using jQuery

I want to do something with data from dynamically generated element, like printing the data from the clicked element, how can I do that?

here's my jquery code:

let setHistory = () => {
   $('#transaction-history').empty();
    transactionHistory.forEach((o) => {
        var htmlBlock = "";
        htmlBlock += `<div class="btn btn-outline transaction-history-item d-flex flex-column justify-content-center mr-4">`
            + `<img class="transaction-history-item-image card pl-2 pr-2 pt-1 pb-1 mx-auto" src="../assets/placeholder-image.png" alt="" >`
            + `<div class="transaction-history-number mt-1 mx-auto">${o.meterNumber}</div>`
            + `<div class="transaction-history-value mx-auto" data-value=${o.value}>Rp${o.value.toLocaleString().replaceAll(',','.')}</div>`
            + `</div>`;
        $('#transaction-history').append(htmlBlock);
    });
}

and the transactionHistory data looks like this:

 let transactionHistory = [
    {
        meterNumber: "1234152322",
        value: 250000
    },
    {
        meterNumber: "1115648463",
        value: 50000
    }
]

and here's the illustration of the dynamically generated element: enter image description here

Basically, I want to get the meterNumber and value from the card I clicked, how can I implement that?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can get desired data by using next() selector or parent() jQuery functions.

Codepen example

using next() function :

$(document).on('click', '.transaction-history-item-image', function() {

    var tranNumber = $(this).next().html();
    var tranValue = $(this).next().next().html();

});

or by using parent() and find() :

$(document).on('click', '.transaction-history-item-image', function() {

    var tranNumber = $(this).parent().find('.transaction-history-number').html();
    var tranValue = $(this).parent().find('.transaction-history-value').html();

});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!