javascript - How to get inner id/class from div? -


this question has answer here:

i have this:

<div id="container"></div> 

this html. inside of container, add other div elements using jquery.

$(document).ready(function () {     $.get("/ask", {}, function (response, status) {         $.each(response.cars, function (index, val) {             $("#container").append("<div class = 'q' id=" + val.id + "\">" + val.carname + "<br>" + val.date + "</div>");         });     });      $("div").click(function (e) {         e.stoppropagation();         alert($(this).attr("id"));     }); }); 

on click, want retrieve id inner divs (they 1, 2, 3) whenever click on of divs added using jquery, shows container or nothing @ all. how can id added divs? tried with:

$(".q").click(function(){     alert($(this).attr("id")); }); 

you can try this...

$( "#container" ).on( "click", ".q", function() {   alert($(this).attr("id")) }); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -