jquery - getting class of dynamicly created parent element on keypress in dynamicly created child input -


Good day I need to get a dynamically generated div id when I dynamically build input inside that div Hit a key in I create them at the same time after clicking on the button:

HTML:

  & lt; Div id = "known" & gt; & Lt; Button ID = "Create" & gt; Create & lt; / Button & gt; & Lt; / Div & gt;  

Jquery:

  $ (document) .ready (function () {$ ("# create") .On ("click", function ( ) {Var num = 0; $ ("# known") enclosed ("

This part is very clear, but when I have to attach the function, I can not solve the problem because this id does some work, so it will work. I tried it like this:

  $ ("Get_id"). ("Keypress", function () {var id = $ (this) .Parent (). Attr ("id"); warning (id);});  

But it is used to work, because the element does not exist with the class get_id when the page loads, and if I add it to the next higher element which is in its div Existed, so I can not use the original work to get that ID, because it will give me a recognizable id, is it possible anyway? thanks for your cooperation.

Put them in the same click function and keep num as outgoing

  $ (document) .ready (function () {var num = 0; $ ("# create") On ("click", function () {$ ("# known"). Enclosed ("& lt ; Div id = 'unknown_ "+ num +"' & gt; & lt; input type = 'text' class = 'get_id' / & gt; & lt; / div & gt; "); num ++; $ ( ". Get_id") .on ("keypress", function () {var id = $ (this) .Parent (). Attr ("id"); alert (id);});});});  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -