Below is a fiddle I am experimenting with. Basically I am looking to update the dynamically appended spans to the preview div when there is a change in value on the input fields. The value of the input is available in the alert, but it does not seem to be updating the span. I also find it strange that if you simply select the span with the dynamically generated ID and alert the text, that it has no value. Any thoughts? I am avoiding using knockout for what it is worth.
$(document).ready(function(){
$(".project").each(function(index, value){
var titleElem = $(this).find(':nth-child(1)');
var projId = "#" + titleElem.attr('id') + "_Prev";
$("#previews").append("<span id='" + projId + "'>" + titleElem.val() + "</span><br/>");
titleElem.keyup(function(){
alert($(this).val());
$(projId).text($(this).val());
});
});
});
The goal is a I want this logic to be able to handle any number of project divs that might show up on the view.
idof yourspanincorrectly. You're including the#character in theid, which you should not (though you do, of course, need it in the jQuery selector when getting the element from the DOM. Just out of curiousity, why are you trying to avoid Knockout (and all the other databinding libraries out there)?