Answer the question
In order to leave comments, you need to log in
Why is the element created but not rendered by JS in any way?
There is a code that creates a block
var buttonid = 0; // глобальная переменная где-то вначале
$(document).ready(function(){
$("#addbutton").click(function(){
$(".block").append('<span>Кнопка '+buttonid+'</span>');
buttonid++;
})
$("span").click(function(){
alert($(this).text()); // не возвращает нужного результата.
})
})
Answer the question
In order to leave comments, you need to log in
$(document).on("span", 'click', function() {
alert($(this).text()); // не возвращает нужного результата.
});
var buttonid = 0; // глобальная переменная где-то вначале
$(document).ready(function(){
$("#addbutton").click(function(){
var item = $('<span>Кнопка '+buttonid+'</span>');
$(".block").append(item);
buttonid++;
item.click(function(){
alert($(this).text());
})
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question