简体   繁体   中英

How to select elements added with jQuery?

I have HTML table. I get data from Firebase and append that data to my HTML table, with classes.

I'm trying to figure out how to select that appended data on my HTML and update values, because my values changes by time (I do some math with time).

I know the way to select using on.('click'), but I would like to select it and update it without any click events.

var frequency = snapshot.val().frequency;
var recordKey = snapshot.key;
var minsAway = frequency - (firstCurrentDiff % frequency);
var nextArrival = moment().add(minsAway, "minutes").format("HH:mm")
var row = $("<tr>").attr("class", recordKey);

row.appendTo("#tableBody");
$("<td>" + frequency + "</td>").appendTo(row);
$("<td>" + nextArrival + "</td>").appendTo(row);
$('<td class="mins-away">' + minsAway + "</td>").appendTo(row);

If i get what you need, after append, you can get it with :last

row.appendTo("#tableBody");
$myrow = $("#tableBody tr:last");

And then, for ex, refer to each td or find specific one:

$td_mins_away = $myrow.find('td.mins-away');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM