使加载的元素成为jQuery对象

使加载的元素成为jQuery对象,jquery,ajax,Jquery,Ajax,正如我在jQuery中使用Ajax所发现的,加载的元素不是jQuery对象。“重新扫描”文档以使元素加载Ajax jQuery对象的最佳方法是什么 在下面的代码jq('.storyBlock button')。单击(function(),其他函数不会在加载的Ajax html上启动。如何最好地更改此代码,使其启动 var jq = jQuery.noConflict(); jq(document).ready(function() { // Disable buttons after

正如我在jQuery中使用Ajax所发现的,加载的元素不是jQuery对象。“重新扫描”文档以使元素加载Ajax jQuery对象的最佳方法是什么

在下面的代码
jq('.storyBlock button')。单击(function()
,其他函数不会在加载的Ajax html上启动。如何最好地更改此代码,使其启动

var jq = jQuery.noConflict();

jq(document).ready(function() {
    // Disable buttons after clicking
    jq('.storyBlock button').click(function() {
        jq(this).addClass('selected');
        jq(this).parent().addClass('disabled');
        jq(this).parent().find('button').attr('disabled', true);
    });
    // Event Handler
    jq('.storyBlock button').click(function() {
        // Find link
        var getID = jq(this).data('link');
        console.log(getID + '.html');

        // Load file and insert after last story
        jq.ajax(getID + '.html').done(function(html) {
        jq('#stories > div:last-child').after(html);
        if ( (getID) != 'start' ) {
            jq('html,body').animate({ scrollTop: jq('#' + getID).offset().top },'slow');
        } else {
            jq('.storyBlock').remove();
            jq('#stories > div' ).load( "start.html" );
            jq('html,body').animate({ scrollTop: jq('#start').offset().top },'slow');
        }
       });
    });
});
您需要使用,因为您需要处理动态元素

因此,将事件处理程序转换为

jq(document).on('click', '.storyBlock button', function() {
})

!!!@ArunPJohny是正确的。如果要向DOM动态添加元素,则需要使用事件delegation@ArunPJohny我认为大喊“活动代表团!!!”是没有用的在OP和/或downvote上,即使问题涉及到所涉及的技术的基本概念,也要对这个问题进行投票。@Filburt我没有投票反对……但提供的链接将有助于解决问题。感谢您的快速回复。我仍然不确定如何将此功能应用于我上面的代码以使其正常工作。类似这样的内容:
$(文档).on(加载,函数(){});