在新创建的dom元素上使用jQUery hide() [英] Using jQUery hide() on newly created dom elements

查看:110
本文介绍了在新创建的dom元素上使用jQUery hide()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery比较陌生.我有一个应用程序,该应用程序在表中显示数据库中的内容项列表.

I am relatively new to jQuery. What I have is an app that is displaying a list of content items from the database in a table.

如果我单击页面的标题链接,它将在选项卡中加载要编辑的页面(单击选项卡可让我查看要编辑的表单).

If I click the title link of the page, it will load the page to edit in a tab (clicking teh tab lets me view that form to edit).

我的问题是,在使用.load并在空div内创建html时,以前由jQuery隐藏的css不再以这种新形式隐藏.

My problem is that in using .load and creating the html inside an empty div, my css that was previously hidden by jQuery is no longer being hidden in this new form.

例如,在同一页面上,我有一个类错误的div.这是隐藏的.我单击标题进行编辑,页面加载到一个空的div中,并且没有隐藏作为类错误的div.

For example, on the same page, I have a div with the class error. This is hidden. I click the title to edit, the page loads in an empty div, and the divs with error as a class are not hidden.

有没有办法使这些元素隐藏起来?

Is there a way around this to get these elements hidden?

推荐答案

以下是我将其他URL的内容加载到当前页面的一部分中时始终使用的代码:

Here is the code that I always use when loading content from other url into a section of current page:

jQuery(function($){
  $("#edit").click(function(){
    //display loading message in target div, it's better have animation gif
    $('#target').html('<img src="PATH/loading.gif" alt="" /> Loading edit form...');
    //request the edit form using AJAX
    $.get(EDIT_FORM_URL,
      {},
      function(data){
        //display data to target div
        $('#target').html(data);
        //if the error div still displayed, do this
        $(".error").hide();
      });
  });
});

我从不使用.load.我更喜欢使用$.get$.post来进行更多控制,但不如$.ajax那样复杂.

I never use .load. I prefer to use $.get and $.post instead for more control, but not as complex as $.ajax.

希望获得帮助.如果您仍然得到一个奇怪的结果,请在此处发布代码或URL,以便其他SO成员可以更准确地为您提供帮助.

Hope this help. If you still get a weird result, post the code or URL here, so other SO member can help you more accurately.

这篇关于在新创建的dom元素上使用jQUery hide()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆