How to catch $(".tag")
click which added by ajax, I try to use .live()
, .on()
and .bind()
but where is no result
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var content = $("#ad_content").val();
$.ajax({
type: "GET",
url: "tags/check",
data: {
content: content
},
dataType: "text",
success: function(tags) {
var tag, tags_html, _i, _len, _ref;
if (tags === "[null]") {
return $(".tags").html("");
} else {
tags_html = "";
_ref = jQuery.parseJSON(tags);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
tag = _ref[_i];
tags_html += "<span class=\"tag\">" + tag + "<a class=\"websymbol\" href=\"javascript:;\">Î</a></span>";
}
$(".tags").html(tags_html);
}
}
});
$(".tag").on("click", function() {
alert("123");
});
});
</script>
<textarea id="ad_content">2222</textarea>
<div class="tags"></div>