jquery - Access element after append -


i've read through every post can find on topic , have tried many "solutions" doesn't seem working me.

$(function () {      var options = {         source: [             "actionscript",             "applescript",             "asp",             "basic",             "c",             "c++",             "clojure",             ],         minlength: 2     };        $('#btn_addline').on ("click", function () {          // existing line number , increment 1         var linenum = parseint ($('#numlines').val()) + 1;          // update hidden numlines field new value         $('#numlines').val(linenum);          // define new field names         var line_field = 'report['+linenum+'][line]';         var notes_field = 'report['+linenum+'][notes]';         var contact_field = 'report['+linenum+'][contact]';          var newline = $('<tr> \             <td><input name="'+line_field+'" id="'+line_field+'" type="text" size="2" maxlength="2" class="form" value="'+linenum+'" readonly="readonly" /></td> \             <td><input name="'+notes_field+'" id="'+notes_field+'" type="text" size="96" maxlength="256" class="form" /></td> \             <td><input name="'+contact_field+'" id="'+contact_field+'" onfocus="attach_autocomplete()" type="text" size="32" maxlength="32" class="form" value="test123" /></td> \             </tr>');          // append new line table         //$('#report_items').append(newline);          $('#report_items').append(newline)             .hide()             .fadein('normal', function() {                 $(this).find('#'+contact_field).val('test');                 //alert ($(this).find('#'+contact_field).val());                 alert (contact_field);                 alert ($('#'+contact_field).val());             });          //$('#'+contact_field).autocomplete(options);      }); }); 

the new html appended properly, nothing can access elements. i've tried various suggestions throughout site , frustrated , hoping help.

the third alert - alert ($('#'+contact_field).val()); - returns "undefined".

to clear, have thoroughly gone through list of similar questions, have not found solution. possible missing obvious, or don't quite understand relation between appending elements , it's effect on dom, in case use hand here.

cheers.

the problem have special characters within selector. you'd need escape 2 backslashes \\:

to use of meta-characters ( such !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) literal part of name, must escaped with 2 backslashes: \. example, element id="foo.bar", can use selector $("#foo\.bar").

check out documentation


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -